leetcode [#22] | GCidea's blog
目录

题目
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:
[
“((()))”,
“(()())”,
“(())()”,
“()(())”,
“()()()”
]
解决方案
1 | public class Solution { |
注意事项
- 不应该从找规律的角度入手,这样即便得到可能情况的总数,但生成具体字符串时还比较麻烦。
- recursivelyGetParenthesis()方法的作用是,逐步生成结果字符串,当长度满足时就作为一个符合要求的结果返回,否则,在当前片段的基础上递归调用自身,生成新的结果。