1
class Solution {
2
public String removeOuterParentheses(String s) {
3
// if '(' check stack size > 0 add ans else not add ans
4
// if ')' check stack size > 0 add ans else not add ans
5
Stack<Character> st = new Stack<>();
6
StringBuilder sb = new StringBuilder();
7
for (int i = 0; i < s.length(); i++) {
8
char ch = s.charAt(i);
9

10
if (ch == '(') {
11
if (st.size() > 0) {
12
sb.append(ch);
13
}
14
st.push(ch);
15
} else {
16
st.pop();
17
if (st.size() > 0) {
18
sb.append(ch);
19
}
20
}
21
}
22
return sb.toString();
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0