Description
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Examples
Input:
n = 3Output:
["((()))","(()())","(())()","()(())","()()()"]Explanation:
All valid combinations of 3 pairs of parentheses.
Input:
n = 1Output:
["()"]Explanation:
Only one valid combination.
Input:
n = 4Output:
["(((())))","((()()))","((())())","((()))()" ,"(()(()))","(()()())","(()())() ","(())(())","(())()() ","()((()))","()(()())","()(())() ","()()(())","()()()() "]Explanation:
For 4 pairs of parentheses, there are 14 valid combinations. Each combination uses exactly 4 opening and 4 closing parentheses, with every opening parenthesis properly matched to a closing one, and no closing parenthesis appearing before its corresponding opening parenthesis.
Constraints
- •
1 ≤ n ≤ 8