算法——求n对()有多少种输出方式?
2024-09-06 17:23:02
letcode:22
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
public List<String> generateParenthesis(int n) {
List<String> res = new ArrayList<>();
gen(res, n, n, "");
return res;
} private void gen(List<String> res, int left, int right, String str) {
if (left == 0 && right == 0) {
res.add(str);
return;
}
if (left > 0) {
gen(res, left - 1, right, str + "(");
}
if(right > left){
gen(res, left, right - 1,str + ")");
}
}
最新文章
- 魔法禁书目录2:回家(codevs 3024)
- windowsapi
- 汇编学习(六)&mdash;&mdash;代码转换程序
- [SAP ABAP开发技术总结]客户端文本文件、Excel文件上传下载
- ASP.NET Eval四种绑定方式
- oracle11g安装成功
- Atom编辑器入门到精通(三) 文本编辑基础
- phpquery笔记
- Java Keyword -- super
- SDI接口
- Socket在手机上的应用
- ruby中如何调用与局部变量同名的私有方法
- 在阿里云开源镜像站中下载centOS7
- pip3 升级失败的解决方法!亲测有效
- 用vi编辑文件
- Swagger2使用参考
- String s = new String(";xyz";);产生了几个对象?
- [Leetcode 55]跳格子JumpGame
- Java网络通信 TCP网络,ServerSocket类
- Swoole 结合TP5创建http服务
热门文章
- LeetCode.944-删除列保证排序(Delete Columns to Make Sorted)
- 20个python项目--图片转字符画
- 【miscellaneous】星光级超低照度摄像机技术分析
- c语言l博客作业11
- 插入排序--python
- [Python3] 032 常用模块 random
- WorkStation Linux 客户端 虚拟机的使用过程
- Spark中的术语图解总结
- C++中的异常处理(上)
- [Codeforces 1245D] Shichikuji and Power Grid (最小生成树)