Skip to content

Commit 44b0e00

Browse files
authored
Merge pull request #3403 from an0nh4x0r/patch-1
Update 0022-generate-parentheses.java
2 parents b9f60c2 + 014eacc commit 44b0e00

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

java/0022-generate-parentheses.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ public List<String> generateParenthesis(int n) {
2222

2323
private void backtrack(int openN, int closedN, int n) {
2424
if (openN == closedN && closedN == n) {
25-
Iterator vale = stack.iterator();
26-
String temp = "";
27-
while (vale.hasNext()) {
28-
temp = temp + vale.next();
25+
StringBuilder sb = new StringBuilder();
26+
for (Character c: stack) {
27+
sb.append(c);
2928
}
30-
res.add(temp);
29+
res.add(sb.toString());
3130
}
3231
if (openN < n) {
3332
stack.push('(');

0 commit comments

Comments
 (0)