public class Solution {
public int evalRPN(String[] A) {
Stack<Integer> st = new Stack<>();
for (int i = 0; i < A.length; i++) {
if (A[i].compareTo("+") == 0) {
int num1 = st.pop();
int num2 = st.pop();
st.push(num2 + num1);
} else if (A[i].compareTo("-") == 0) {
int num1 = st.pop();
int num2 = st.pop();
st.push(num2 - num1);
} else if (A[i].compareTo("*") == 0) {
int num1 = st.pop();
int num2 = st.pop();
st.push(num2 * num1);
} else if (A[i].compareTo("/") == 0) {
int num1 = st.pop();
int num2 = st.pop();
st.push(num2 / num1);
} else {
st.push(Integer.parseInt(A[i]));
}
}
return st.pop();
}
}