Generate all combinations of well-formed parentheses strings of length .
Given an integer n, generate every distinct string that contains exactly n left parentheses ( and n right parentheses ) and is a valid well-formed parentheses sequence.
A parentheses string is valid if:
( as ).( equals the total number of ).Return all valid combinations in any order.
n.n pairs.n.n representing the number of pairs of parentheses.n pairs.n opening and n closing parentheses.Example 1
Input
n = 3
Output
["((()))","(()())","(())()","()(())","()()()"]
Explanation
There are five valid sequences using exactly three pairs of parentheses.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.