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