classSolution{ publicintevalRPN(String[] tokens){ Stack<Integer> s = new Stack<>(); for (String t: tokens){ if ("+".equals(t)){ int b = s.pop(); int a = s.pop(); int ans = a + b; s.push(ans); } elseif ("-".equals(t)){ int b = s.pop(); int a = s.pop(); int ans = a - b; s.push(ans);
} elseif ("*".equals(t)){ int b = s.pop(); int a = s.pop(); int ans = a * b; s.push(ans); } elseif ("/".equals(t)){ int b = s.pop(); int a = s.pop(); int ans = a / b; s.push(ans); } else{ int num = Integer.parseInt(t); s.push(num); } } return s.peek(); } }