0022. Generate Parentheses
Medium | String + DP | 28 ms (95.96%), 14.5 MB (87.81%)
Source: LeetCode - Generate Parentheses GitHub: Solution / Performance
Given n
pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
We generate new combinations of well-formed parentheses based on previous iteration's results. Thus, it is a DP question.
Pattern 1: Add outer parenthesis by iterating previous results
Pattern 2: Try all orders for all previous results and then perform set union.
Last updated