Skip to content

Commit 1841f8a

Browse files
authored
Create Generate Parentheses
1 parent bb69473 commit 1841f8a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public List<String> generateParenthesis(int n) {
3+
4+
List<String> res = new ArrayList<>();
5+
findAll("(", 1, 0, res, n);
6+
return res;
7+
}
8+
9+
void findAll(String current, int o, int c, List<String> res, int n){
10+
11+
if(current.length()== 2*n){
12+
res.add(current);
13+
return;
14+
}
15+
if(o<n) findAll(current+"(", o+1, c, res, n);
16+
if(c<o) findAll(current + ")", o, c+1, res, n);
17+
18+
}
19+
}

0 commit comments

Comments
 (0)