首页 > 其他 > 详细

#栈#leetcode856.括号的分数

时间:2020-07-15 22:35:28      阅读:46      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

 

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();
    }
}

 

#栈#leetcode856.括号的分数

原文:https://www.cnblogs.com/lyr-2000/p/13307934.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!