Skip to content

Commit 91beabd

Browse files
committed
update 1021.remove-outermost-parentheses.java
1 parent e3c0e9e commit 91beabd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

1021.remove-outermost-parentheses.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ public String removeOuterParentheses(String S) {
9898
// stacked openings, then it pops off from the stack whenever it finds
9999
// closing.
100100
if (c == '(') {
101-
if (open != 0) sb.append(c);
102101
open++;
102+
if (open == 1)
103+
continue;
103104
} else if (c == ')') {
104105
open--;
105-
if (open != 0) sb.append(c);
106+
}
107+
108+
// If open > 0, Meaning theres, an open outer parenthesis:
109+
// Append into buf
110+
if (open > 0) {
111+
sb.append(c);
106112
}
107113
}
108114

0 commit comments

Comments
 (0)