import java.util.*;
public class Solution {
public int evalRPN (String[] tokens) {
// write code here
Stack<Integer> stack = new Stack<>();
// 注意这里是要把每次的结果也一起压入栈中,继续计算
for(String token : tokens){
if(!token.equals("+") && !token.equals("-") && !token.equals("*") && !token.equals("/")){
stack.push(Integer.parseInt(token));
}else{
int num1 = stack.pop();
int num2 = stack.pop();
if(token.equals("+")){
stack.push(num1 + num2);
}else if(token.equals("-")){
stack.push(num2 - num1);
}else if(token.equals("*")){
stack.push(num2 * num1);
}else if(token.equals("/")){
stack.push(num2 / num1);
}
}
}
return stack.pop();
}
}