class Solution {
public:
vector<string> r;
vector<string> generateParenthesis(int n) {
string s = "";
h(s, n, n);
return r;
}
void h(string s, int left, int right) {
if(left == 0 && right == 0) {
r.push_back(s);
return;
}
if(left == right) {
h(s + "(", left - 1, right);
}
else if(left < right) {
if(left > 0) {
h(s + "(", left - 1, right);
}
h(s + ")", left, right - 1);
}
}
};
相关文章
- 11-19leetcode-mid-backtracking -22. Generate Parentheses-79 Word Search -NO
- 11-19Generate Parentheses - LeetCode
- 11-19Leetcode 22 - Generate Parentheses.
- 11-19【LeetCode每天一题】Generate Parentheses(创造有效的括弧)
- 11-1922. Generate Parentheses
- 11-1922. Generate Parentheses dfs填表
- 11-19Leetcode22. Generate Parentheses
- 11-19刷题22. Generate Parentheses
- 11-1922. Generate Parentheses(js)
- 11-19【LeetCode每天一题】Generate Parentheses(创造有效的括弧)