Medium Difficulty Question
The number n
represents how many pairs of brackets are generated. Please design a function, which is able to generate all possible valid parenthesis combinations.
E.g. 1:
Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"]
E.g. 2:
Input: n = 1 Output: ["()"]
where n>0
This is a combinatory problem. We notice that there's a bijection between the set of all valid brackets combinations and the set of all 2n-length Dyck Paths
. Here's a