若 A=10、B=4、C=6、D=4、E=15 则后缀表达式“ AB*CD+-E+ ”的值为 ( ) 。
class Solution {
public int evalRPN(String[] tokens) {
ArrayDeque<Integer> stack = new ArrayDeque<>();
for (String token : tokens) {
if (token.equals("+") || token.equals("-") || token.equals("*") || token.equals("/")) {
int b = stack.poll();
int a = stack.poll();
if (token.equals("+")) {
stack.push(a + b);
} else if (token.equals("-")) {
stack.push(a - b);
} else if (token.equals("*")) {
stack.push(a * b);
} else {
stack.push(a / b);
}
} else {
stack.push(Integer.valueOf(token));
}
}
return stack.poll();
}
}