from typing import List
class Solution:
def evalRPN(self, tokens: List[str]) -> int:
stack = []
for token in tokens:
if token in {'+', '-', '*', '/'}:
b = stack.pop()
a = stack.pop()
if token == '+':
stack.append(a + b)
elif token == '-':
stack.append(a - b)
elif token == '*':
stack.append(a * b)
elif token == '/':
# Ensure b is not zero to avoid division by zero error
if b == 0:
raise ValueError("Division by zero encountered")
stack.append(int(a / b)) # Assuming integer division is intended
else:
stack.append(int(token))
return stack[0] # The final result is on top of the stack