0022. Generate Parentheses
Medium | String + DP | 28 ms (95.96%), 14.5 MB (87.81%)
Last updated
Was this helpful?
Medium | String + DP | 28 ms (95.96%), 14.5 MB (87.81%)
Last updated
Was this helpful?
Source: GitHub:
Given n
pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Pattern 1: Add outer parenthesis by iterating previous results
Pattern 2: Try all orders for all previous results and then perform set union.