Skip to content

Generate Parantheses ​

Generate Parantheses — LeetCode

Given n pairs of parentheses, generate all combinations of well-formed parentheses.

Approach ​

Backtracking: Start string with ( If open < n, then append a ( and recurse. Backtrack. If open > closed, then append a ) and recurse. Backtrack.

Base case Check if open = closed = n -> append string to result.

Remarks ​