class Solution {
private:
vector<string> result;
string str;
public:
void backtracking(int n, int l, int r){
if(l == n && r == n){
result.push_back(str);
return;
}
if(l < n){
str.push_back('(');
backtracking(n, l + 1, r);
str.pop_back();
}
if(r < l){
str.push_back(')');
backtracking(n, l, r + 1);
str.pop_back();
}
}
vector<string> generateParenthesis(int n) {
int l = 0, r = 0;
backtracking(n, l, r);
return result;
}
};
标签:int,back,生成,力扣,括号,result,str,push,backtracking
From: https://blog.csdn.net/why_12134/article/details/141279297