150. Evaluate Reverse Polish Notation 发表于 2022-08-24 12345678910111213141516171819202122232425262728293031class Solution { public int evalRPN(String[] tokens) { Stack<Integer> numStack = new Stack<>(); for (String token : tokens) { switch (token) { case "+": { numStack.push(numStack.pop() + numStack.pop()); break; } case "-": { int b = numStack.pop(), a = numStack.pop(); numStack.push(a - b); break; } case "*": { numStack.push(numStack.pop() * numStack.pop()); break; } case "/": { int b = numStack.pop(), a = numStack.pop(); numStack.push(a / b); break; } default: numStack.push(Integer.parseInt(token)); } } return numStack.pop(); }} Reference150. Evaluate Reverse Polish Notation剑指 Offer II 036. 后缀表达式