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;
}
}
浙公网安备 33010602011771号