Generate Parentheses
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:
"((()))", "(()())", "(())()", "()(())", "()()()".
Solution: If we have k < n left brackets, we can add a left bracket.
If the number of right brackets < the number of left brackets, we can add a right bracket.
Solution: If we have k < n left brackets, we can add a left bracket.
If the number of right brackets < the number of left brackets, we can add a right bracket.
Comments
Post a Comment