How to solve: Leetcode#22 Generate parentheses

LeetCode — 22. Generate Parentheses Given n pairs of parentheses, generate all combinations of well-formed parentheses. This is one of those problems where the final solution can look almost suspiciously simple: if (closeUsed generateParenthesis(int n) { final res = []; final List stack = [ ('', 0, 0), ]; while (stack.isNotEmpty) { final (cur, openUsed, closeUsed) = stack.removeLast(); if (openUsed == n && closeUsed == n) { res.add(cur); continue; } if (openUsed addIfValid(combination, result) ) return result Then: explorePossibleCombination(n, onFound): ... and: addIfValid(combination, result
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in