class Solution { public int scoreOfParentheses(String S) { //定义 ( 为 0 Deque<Integer> s = new LinkedList<>(); s.push(0); for(char c : S.toCharArray()) { if(c== ‘(‘) { s.push(0); }else{ int top = s.pop(); int pre = s.pop(); s.push(Math.max(2*top,1)+pre); } } return s.pop(); } }
原文:https://www.cnblogs.com/lyr-2000/p/13307934.html