We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
难度:中等 来源:22. 括号生成
数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。
示例 1:
输入:n = 3 输出:["((()))","(()())","(())()","()(())","()()()"]
示例 2:
输入:n = 1 输出:["()"]
提示:
1 <= n <= 8
思路:
()
()()
题解:
/** * @param {number} n * @return {string[]} */ var generateParenthesis = function(n) { let res = [] let dfs = (curStr, left, right) => { if (curStr.length === n * 2) { res.push(curStr) return } if (left > 0) { dfs(curStr + '(', left - 1, right) } if (right > left) { dfs(curStr + ')', left, right - 1) } } dfs('', n, n) return res };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
难度:中等
来源:22. 括号生成
数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。
示例 1:
示例 2:
提示:
思路:
()
的长度为 2, n = 2 则路径()()
的长度为 4 ,路径的最大长一定是 n 的 2 倍的,这是一个很重要的条件。题解:
The text was updated successfully, but these errors were encountered: