import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tokens string字符串一维数组 * @return int整型 */ public int evalRPN (String[] tokens) { // write code here Stack<String> stack = new Stack<>(); for (String token : tokens) { if (token.equals("+") || token.equals("-") || token.equals("*") || token.equals("/")) { int b = Integer.valueOf(stack.pop()); int a = Integer.valueOf(stack.pop()); int c = 0; if (token.equals("+") ) c = a + b; if (token.equals("-") ) c = a - b; if (token.equals("*") ) c = a * b; if (token.equals("/") ) c = a / b; stack.push(String.valueOf(c)); } else { stack.push(token); } } if (!stack.isEmpty()) return Integer.valueOf(stack.pop()); else return 0; } }