/*
用stack依次存入 string 按照功能实现就好
注意 string的比较要用equals 不能用==; char可以用 ==;
*/
class Solution {
public int calPoints(String[] ops) {
if(ops == null || ops.length == 0) return 0;
Stack<Integer> stack = new Stack<>();
for(String s : ops) {
if(s.equals("C")) {
stack.pop();
continue;
}
if(s.equals("D")) {
int temp = stack.peek();
stack.push(temp * 2);
continue;
}
if(s.equals("+")) {
int last = stack.pop();
int lastSecond = stack.peek();
int sum = last + lastSecond;
stack.push(last);
stack.push(sum);
continue;
}
int num = Integer.valueOf(s);
stack.push(num);
}
int result = 0;
while(!stack.isEmpty()) {
result += stack.pop();
}
return result;
}
}