题目:
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:
“((()))”, “(()())”, “(())()”, “()(())”, “()()()”
分析:对于一个给定的n,有效的括号必定包括n个’(‘和n个’)’,并且每一个’)’前面所包含的’(‘的数量不小于现在的’)’的数量。
代码:
1 |
def combine(self, pre, l, r, result): |
近期评论