Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created November 4, 2018 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/b6a5bf7b87b7e74550724952e7827865 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/b6a5bf7b87b7e74550724952e7827865 to your computer and use it in GitHub Desktop.
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