1 2 3 4 5 6 7 8 9 10 11 12
| class Solution: def evalRPN(self, tokens: List[str]) -> int: stack = [] for item in tokens: if item not in {"+", "-", "*", "/"}: stack.append(item) else: num1, num2 = stack.pop(), stack.pop() stack.append( int(eval(f'{num2} {item} {num1}')) ) return int(stack.pop())
|