1
class Solution {
2
public:
3
int scoreOfParentheses(string s) {
4
stack<int> st;
5
int score = 0;
6
for (int i = 0; i < s.size(); i++) {
7
if (s[i] == '(') {
8
st.push(score);
9
score = 0;
10
} else {
11
score = st.top() + max(2 * score, 1);
12
st.pop();
13
}
14
}
15
return score;
16
}
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0