题目描述:
https://leetcode-cn.com/problems/generate-parentheses/
思路:
代码实现:
class Solution {
public:
vector<string> generateParenthesis(int n) {
vector<string> res;
helper(n, n, "", res);
return res;
}
void helper(int left, int right, string out, vector<string>& res){
if(left>right) return;
if(left ==0 && right==0) res.push_back(out);
else{
if(left>0) helper(left-1, right, out+'(', res);
if(right>0) helper(left, right-1, out+')', res);
}
}
};
参考:回溯与递归https://blog.csdn.net/ajianyingxiaoqinghan/article/details/79682147