-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate_Parentheses
More file actions
43 lines (39 loc) · 873 Bytes
/
Generate_Parentheses
File metadata and controls
43 lines (39 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public:
string tmp;
vector<string> result;
int stnum;
int leftnum;
void dfs(){
if (leftnum==0 && stnum==0){
result.push_back(tmp);
return;
}
if (leftnum>0){
leftnum--;
stnum++;
tmp.push_back('(');
dfs();
tmp.pop_back();
stnum--;
leftnum++;
}
if(stnum>0){
stnum--;
tmp.push_back(')');
dfs();
tmp.pop_back();
stnum++;
}
}
vector<string> generateParenthesis(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
tmp="";
result.clear();
stnum=0;
leftnum=n;
dfs();
return result;
}
};