Evaluate Reverse Polish Notation LeetCode solution in Java

1
class Solution {
2
public int evalRPN(String[] tokens) {
3
Stack<Integer> stack = new Stack();
4
for (String i : tokens) {
5
if (i.equals("+") || i.equals("-") || i.equals("*") || i.equals("/")) {
6
int a = stack.pop();
7
int b = stack.pop();
8
int temp = 0;
9
if (i.equals("+")) temp = a + b;
10
else if (i.equals("-")) temp = b - a;
11
else if (i.equals("*")) temp = a * b;
12
else if (i.equals("/")) temp = b / a;
13
stack.push(temp);
14
} else stack.push(Integer.parseInt(i));
15
}
16
return stack.pop();
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0