-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22.cpp
More file actions
31 lines (29 loc) · 667 Bytes
/
22.cpp
File metadata and controls
31 lines (29 loc) · 667 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
//
// 22.cpp
// leetcode
//
// Created by R Z on 2018/2/4.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;
class Solution {
private:
vector<string> res;
public:
vector<string> generateParenthesis(int n) {
if(n<1) return res;
generate("",0,0,n);
return res;
}
void generate(string str, int left, int right, int max){
if(str.length()==2*max){
res.push_back(str);
return;
}
if(left<max) generate(str+"(",left+1,right,max);
if(right<left) generate(str+")",left,right+1,max);
}
};