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;
}
};
12-03
108
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-21
277
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-08