Generate Parentheses
Given n, return every string made of n opening and n closing parentheses that is balanced: reading from the left, the closing ones never outnumber the opening ones. Return them in any order.
Constraints
- 1 ≤
n≤ 8
Example 1
Input
n = 3
Output
["((()))","(()())","(())()","()(())","()()()"]
Why:
The five balanced strings of three pairs.
Example 2
Input
n = 1
Output
["()"]
Why:
Only one.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –