Evaluate Reverse Polish Notation
class Solution:
def evalRPN(self, tokens: List[str]) -> int:
tokens.reverse()
stk = []
while tokens:
c = tokens.pop()
if c in '+-*/':
if c == '+':
c2 = stk.pop()
c1 = stk.pop()
stk.append(c1 + c2)
elif c == '-':
c2 = stk.pop()
c1 = stk.pop()
stk.append(c1 - c2)
elif c == '*':
c2 = stk.pop()
c1 = stk.pop()
stk.append(c1 * c2)
elif c == '/':
c2 = stk.pop()
c1 = stk.pop()
stk.append(int(c1 / c2))
else:
stk.append(int(c))
return stk.pop()