#栈#leetcode856.括号的分数
时间:2020-07-15 22:35:28
收藏:0
阅读:51
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
评论(0)