class Solution {
public int evalRPN(String[] tokens) {
Stack<Integer> integerStack = new Stack<>();
for (String token : tokens) {
char c = token.charAt(0);
if (c - 48 < 0 && token.length() == 1) {
Integer pop1 = integerStack.pop();
Integer pop2 = integerStack.pop();
Integer multiply = mustily(pop1, pop2, c);
integerStack.add(multiply);
} else {
Integer integer = Integer.valueOf(token);
integerStack.add(integer);
}
}
return integerStack.pop();
}
public Integer mustily(Integer pop1, Integer pop2, Character c) {
if (c == '+') {
return pop2 + pop1;
}
if (c == '-') {
return pop2 - pop1;
}
if (c == '*') {
return pop2 * pop1;
}
return pop2 / pop1;
}
}