LeetCode682

class Solution {
    public int calPoints(String[] operations) {
        int[] a = new int[1000];
        int j =0;
        int sum = 0;
        for(int i=0;i<operations.length;i++){
                if("+".equals(operations[i])){
                    a[j] = a[j-1]+a[j-2];
                    j++;
                }else if("D".equals(operations[i])){
                        a[j] = 2*a[j-1];
                        j++;
                }else if("C".equals(operations[i])){
                        j-=1;
                }else{
                    a[j] = Integer.parseInt(operations[i]);
                    j++;
                }
        }
        for(int k = 0;k<j;k++){
            sum+=a[k];
        }
        return sum;
    }
}
posted @ 2024-07-29 13:56  Sao_maoer  阅读(20)  评论(0)    收藏  举报