Skip to content

Commit c40ea04

Browse files
Time: 4 ms (67.30%), Space: 13.5 MB (66.28%) - LeetHub
1 parent 5767f40 commit c40ea04

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
void myFunc(int n, int o, int c, string str, vector<string>& vec)
4+
{
5+
if(o==n && c==n)
6+
{
7+
vec.push_back(str);
8+
return;
9+
}
10+
11+
if(o<n)
12+
{
13+
myFunc(n, o + 1, c, str + '(', vec);
14+
}
15+
if(c<o)
16+
{
17+
myFunc(n, o , c+1, str + ')', vec);
18+
}
19+
20+
21+
}
22+
vector<string> generateParenthesis(int n) {
23+
vector<string> results;
24+
string str;
25+
myFunc(n, 0, 0, str, results);
26+
return results;
27+
}
28+
};

0 commit comments

Comments
 (0)