Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
vector<string>res;
class Solution {
public:
void choose(string prix,int left,int right,int times,int num){
if(times==num){
string temp =prix+")";
res.push_back(temp);
return;
}
if(left<num/2){
string temp =prix+"(";
choose(temp,left+1,right,times+1,num);
}
if(right<left){
string temp =prix+")";
choose(temp,left,right+1,times+1,num);
}
}
vector<string> generateParenthesis(int n) {
int num =n*2;
int left =0,right=0;
res.clear();
if(n==0) return res;
int times =0;
string prix ="";
choose(prix,left,right,times+1,num);
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment