Generate Parentheses
Medium
LC #22
backtrackingpruningstringsNot attempted yet
Given n, return every well-formed string of n pairs
of parentheses, in any order. Well-formed means every prefix
has at least as many ( as ), and the totals match.
So (() and )( are not allowed.
Example 1
Input: n = 3
Output: ["((()))","(()())","(())()","()(())","()()()"]
Example 2
Input: n = 2
Output: ["(())","()()"]
Constraints
- 1 ≤ n ≤ 8