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