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
Difficulty: 中等
Related Topics: 字符串, 动态规划, 回溯
数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。
n
示例 1:
输入:n = 3 输出:["((()))","(()())","(())()","()(())","()()()"]
示例 2:
输入:n = 1 输出:["()"]
提示:
1 <= n <= 8
Language: JavaScript
/** * @param {number} n * @return {string[]} */ // 回溯法(DFS) var generateParenthesis = function(n) { const res = [] const backtrack = (left, right, str) => { if (left === n && right === n) return res.push(str) if (left < n) backtrack(left + 1, right, str + '(') if (right < left) backtrack(left, right + 1, str + ')') } backtrack(0, 0, '') return res }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
22. 括号生成
Description
Difficulty: 中等
Related Topics: 字符串, 动态规划, 回溯
数字
n
代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。示例 1:
示例 2:
提示:
1 <= n <= 8
Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: