22. Generate Parentheses
来源:互联网 发布:telnet 的端口号是什么 编辑:程序博客网 时间:2024/06/05 15:24
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
[ "((()))", "(()())", "(())()", "()(())", "()()()"]
class Solution { public void handler(List<String> lst, StringBuilder str, int l, int r, int n){ if (str.length() == 2*n){ lst.add(new String(str)); return; } if (l < n){ str.append('('); handler(lst, str, l+1, r, n); str.deleteCharAt(str.length() - 1); } if (l > r){ str.append(')'); handler(lst, str, l, r+1, n); str.deleteCharAt(str.length() - 1); } } public List<String> generateParenthesis(int n) { List<String> lst = new ArrayList<>(); StringBuilder str = new StringBuilder(); handler(lst, str, 0, 0, n); return lst; }}
阅读全文
0 0
- [LeetCode]22.Generate Parentheses
- LeetCode --- 22. Generate Parentheses
- LeetCode 22.Generate Parentheses
- [Leetcode] 22. Generate Parentheses
- 【LeetCode】22.Generate Parentheses
- 22. Generate Parentheses
- [leetcode] 22.Generate Parentheses
- 【leetcode】22. Generate Parentheses
- Leetcode-22.Generate Parentheses
- [leetcode] 22. Generate Parentheses
- 22. Generate Parentheses
- 22. Generate Parentheses
- 22. Generate Parentheses LeetCode
- 22. Generate Parentheses
- leetcode 22. Generate Parentheses
- 22. Generate Parentheses
- [LeetCode]22. Generate Parentheses
- 22. Generate Parentheses
- 从零开始前端学习[29]:Css3中新增加的选择器一
- opencv腐蚀与膨胀
- 常用正则表达式
- Debug日志:char text与char *text的区别
- 滤波反投影重建算法(FBP)实现及应用(matlab)
- 22. Generate Parentheses
- 关于DOS的一些小知识
- 原码、补码、反码
- Java后台框架篇--EL表达式为什么可以取到struts值栈中的值
- 堆、栈在内存中的存储以及程序调用
- 神经网络学习之代价函数详解
- Continuous Integration in DevOps
- 将java源码打成jar包
- 在 Python 中使用 Neo4j