class Solution {
public:
vector<string> res;
void backtrack(int n, string& path, int left, int right){
if(path.length() == n * 2){
res.push_back(path);
return;
}
if(left < n){
path.push_back('(');
backtrack(n, path, left + 1, right);
path.pop_back();
}
if(right < left){
path.push_back(')');
backtrack(n, path, left, right + 1);
path.pop_back();
}
}
vector<string> generateParenthesis(int n) {
string path;
backtrack(n, path, 0, 0);
return res;
}
};
12-09
496
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-25
169
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-20
536
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-20
420
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-30