括号生成
class Solution {
public:
vector<string> result;
vector<string> generateParenthesis(int n) {
//括号生成使用的回溯法
huisu(n,n,n,"");
return result;
}
void huisu(int n,int left,int right,string s)
{
if(left==0&&right==0)
{
result.push_back(s);
return;
}
if(left>0)
huisu(n,left-1,right,s+'(');
if(left<right)
{
huisu(n,left,right-1,s+')');
}
}
};