Created
November 4, 2018 04:23
-
-
Save zhangxiaomu01/12b8781e005dd018aa67e16af3de17ba 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
vector<string>res; | |
class Solution { | |
public: | |
void choose(string prix,int left,int right,int times,int num){ | |
if(times==num){ | |
string temp =prix+")"; | |
res.push_back(temp); | |
return; | |
} | |
if(left<num/2){ | |
string temp =prix+"("; | |
choose(temp,left+1,right,times+1,num); | |
} | |
if(right<left){ | |
string temp =prix+")"; | |
choose(temp,left,right+1,times+1,num); | |
} | |
} | |
vector<string> generateParenthesis(int n) { | |
int num =n*2; | |
int left =0,right=0; | |
res.clear(); | |
if(n==0) return res; | |
int times =0; | |
string prix =""; | |
choose(prix,left,right,times+1,num); | |
return res; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment