Created
October 4, 2018 13:19
-
-
Save z0marlin/6e4408c0e8e4cff6a430502d8a863f6e to your computer and use it in GitHub Desktop.
Webclub codebuddy week1 odd sem 2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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