Skip to content

Commit bbace09

Browse files
authored
Create Solution.java
1 parent ad4b75a commit bbace09

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public String removeOuterParentheses(String S) {
3+
StringBuilder res = new StringBuilder();
4+
int cnt = 0;
5+
for (char c : S.toCharArray()) {
6+
if (c == '(') {
7+
if (++cnt > 1) {
8+
res.append('(');
9+
}
10+
} else {
11+
if (--cnt > 0) {
12+
res.append(')');
13+
}
14+
}
15+
}
16+
return res.toString();
17+
}
18+
}

0 commit comments

Comments
 (0)