blob: 4271beb0700b2ee5d92f0e307427fc0da61033f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<string> result;
void helper(int open, int close, int n, string curr) {
if (curr.length() == n * 2)
result.push_back(curr);
if (open < n)
helper(open + 1, close, n, curr + '(');
if (close < open)
helper(open, close + 1, n, curr + ')');
}
vector<string> generateParenthesis(int n) {
helper(0, 0, n, "");
return result;
}
};
int main() {}
|