import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param tokens string字符串一维数组
* @return int整型
*/
public int evalRPN (String[] tokens) {
// 存储数组数字 遇到运算符时出栈运算
Stack<Integer> stack = new Stack<>();
for (String token : tokens) {
switch (token) {
case "+" :
stack.push(stack.pop() + stack.pop());
break;
case "-" :
Integer val1 = stack.pop();
stack.push(stack.pop() - val1);
break;
case "*" :
stack.push(stack.pop() * stack.pop());
break;
case "/" :
Integer val2 = stack.pop();
stack.push(stack.pop() / val2);
break;
default: stack.push(Integer.valueOf(token));
}
}
return stack.pop();
}
}