Created
November 4, 2018 05:38
-
-
Save zhangxiaomu01/b6a5bf7b87b7e74550724952e7827865 to your computer and use it in GitHub Desktop.
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
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