方法:模拟 class Solution { public int evalRPN(String[] tokens) { Deque<Integer> stack = new LinkedList<>(); for (String token : tokens) { if ("+".equals(token)) { int num2 = stack.pop(); int num1 = stack.pop(); stack.push(num1 + num2); } else if ("-".equals(token)) { int num2 = stack.pop(); int num1 = stack.pop(); stack.push(num1 - num2); } else if ("*".equals(token)) { int num2 = stack.pop(); int num1 = stack.pop(); stack.push(num1 * num2); } else if ("/".equals(token)) { int num2 = stack.pop(); int num1 = stack.pop(); stack.push(num1 / num2); } else { stack.push(Integer.parseInt(token)); } } return stack.pop(); } }