-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path22.cpp
More file actions
executable file
·42 lines (40 loc) · 877 Bytes
/
22.cpp
File metadata and controls
executable file
·42 lines (40 loc) · 877 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
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
class Solution {
public:
void generate(int left, int right, string str, vector<string>& res){
if(left==0&&right==0){
res.push_back(str);
return;
}
if(left>0){
generate(left-1, right, str+'(',res);
}
if(right>left&&right>0){
generate(left,right-1,str+')',res);
}
}
vector<string> generateParenthesis(int n) {
vector<string> res;
generate(n,n,"",res);
return res;
}
};
int main()
{
Solution temple;
vector<string> res1;
res1 = temple.generateParenthesis(3);
for(int i=0;i<res1.size();i++){
cout<<res1[i]<<endl;
}
return 0;
}