Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Solution {
public:
vector<string> generateParenthesis(int n) {
vector<string> res;
if(n == 0)
res.push_back("");
else{
for(int left = 0; left < n; left++){
vector<string> tempL = generateParenthesis(left);
for(int i = 0; i< tempL.size(); i++){
string l = tempL[i];
vector<string> tempR = generateParenthesis(n - left -1);
for(int j = 0; j < tempR.size(); j++){
string r = tempR[j];
res.push_back("(" + l + ")" + r);
}
}
}
}
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment