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
原题链接
题目要求我们生成所有可能的有效的括号组合,数字 n 代表生成括号的对数。
使用回溯法进行解题,从空字符串开始构造,做加法。
const generateParenthesis = function (n) { const res = [] function generate(l, r, str) { // 递归终止条件 if (l === n && r === n) { return res.push(str) } if (l < r) { return } if (l < n) { generate(l + 1, r, str + '(') } if (r < l) { generate(l, r + 1, str + ')') } } generate(0, 0, '') return res }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
回溯法
题目要求我们生成所有可能的有效的括号组合,数字 n 代表生成括号的对数。
使用回溯法进行解题,从空字符串开始构造,做加法。
The text was updated successfully, but these errors were encountered: