Sakura

sakura

博客园 首页 新随笔 联系 订阅 管理

 

 

 

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

 

posted on 2020-07-15 20:58  .geek  阅读(162)  评论(0编辑  收藏  举报