Problem description
Given n pairs of parentheses(括号), write a function to generate all combinations of well-formed parentheses.
Examples
1 | Example 1: |
Solution
和Combinations of a Phone Number类似,都是用回溯法,不过具体运用有些差异。如需要左右指针确定添加左括号还是右括号。先添加左括号深搜下去,直至left == n(PS:左右括号数目均为n),再回溯添加右括号。
Code
1 | class Solution { |