Skip to content

Instantly share code, notes, and snippets.

@z0marlin
Created October 4, 2018 13:19
Show Gist options
  • Save z0marlin/6e4408c0e8e4cff6a430502d8a863f6e to your computer and use it in GitHub Desktop.
Save z0marlin/6e4408c0e8e4cff6a430502d8a863f6e to your computer and use it in GitHub Desktop.
Webclub codebuddy week1 odd sem 2018
string s;
vector<string> ans;
void myFunc(int n,int o,int c){
if(o+c==2*n){
ans.push_back(s);
return;
}
if(o<n){
s.push_back('(');
myFunc(n,o+1,c);
s.pop_back();
}
if(c<o){
s.push_back(')');
myFunc(n,o,c+1);
s.pop_back();
}
}
vector<string> Solution::generateParenthesis(int A) {
s="";
ans.clear();
myFunc(A,0,0);
// sort(ans.begin(),ans.end());
return ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment