- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem22.java
More file actions
Latest commit
23 lines (21 loc) · 611 Bytes
/
Copy pathProblem22.java
File metadata and controls
23 lines (21 loc) · 611 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
importjava.util.*;
classProblem22 {
publicstaticvoidmain(String[] args) {
System.out.println(newProblem22().generateParenthesis(3).size());
}
publicList<String> generateParenthesis(intn) {
List<String> res = newArrayList<String>();
if (n < 1) {
res.add("");
} else {
for (inti = 0; i < n; i++) {
for(Stringleft : generateParenthesis(i)) {
for (Stringright: generateParenthesis(n-1-i)) {
res.add("(" + left + ")" + right);
}
}
}
}
returnres;
}
}