n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
This is a classic recursive problem, in each recursive loop, we need to add one char
) to current state, but with two limitations:
The number of
) in the final state should be equal
In any state, the number of
) should be less or equal to
So we use these parameters in recursive function:
ll : limit number of
lr : limit number of
Preparing for an interview? Check out this!
Join my Email List for more insights, It's Free!😋