其他分享
首页 > 其他分享> > 856. Score of Parentheses

856. Score of Parentheses

作者:互联网

class Solution {
    public int scoreOfParentheses(String s) {
        Stack<Integer> st = new Stack<>();
        int score = 0;
        for(int i = 0; i < s.length(); i++){
            char ch = s.charAt(i);
            if(ch == '('){
                st.push(score);
                score = 0;
            }
            else {                
                if(score==0)
                    score = 1;
                else
                    score = 2*score;
                score += st.pop();
            }
        }
        return score;
    }
}

 

标签:856,Parentheses,score,int,st,ch,Score,else,Stack
来源: https://www.cnblogs.com/feiflytech/p/16164047.html