Generate All Parentheses
MediumP1Coding
Given n pairs of parentheses, return all strings of length 2 * n that are well-formed: every ( is closed by a matching ) in the correct order. Return the strings in any order.
Example 1
- Input
- n = 3
- Output
- ["((()))","(()())","(())()","()(())","()()()"]
Example 2
- Input
- n = 1
- Output
- ["()"]
Constraints
- 1 <= n <= 8
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 7. ⌘Enter runs, ⌘⇧Enter submits.