Generate Parentheses 题解
Last updated
Was this helpful?
Last updated
Was this helpful?
题目来源:
> 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: "((()))", "(()())", "(())()", "()(())", "()()()"
解题思路:
用递归,一个括号一个括号放,只要有左括号在,随时都可以放;放右括号时,已经放好的左括号数量要多余已放好的右括号才可以。