1
class Solution {
2
public int scoreOfParentheses(String s) {
3
Stack<Integer> st = new Stack<>();
4
int score = 0;
5
for (int i = 0; i < s.length(); i++) {
6
char ch = s.charAt(i);
7
if (ch == '(') {
8
st.push(score);
9
score = 0;
10
} else {
11
score = st.pop() + Math.max(2 * score, 1);
12
}
13
}
14
return score;
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0