문제는 간단하다.
후위연산자 계산이다.
문제 링크 : LeetCode - 150. Evaluate Reverse Polish Notation
stack을 사용했다.
stack[-2] + stack[-1]후위연산자 표기법에 대해서는 여기를 확인하자.
class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        stack = []
        operator = ['+', '-', "/", "*"]
        for token in tokens:
            if token not in operator: # number
                stack.append(token)
            else:
                num1 = int(stack.pop())
                num2 = int(stack.pop())
                if token == '+':
                    stack.append(num2 + num1)
                elif token == '-':
                    stack.append(num2 - num1)
                elif token == '*':
                    stack.append(num2 * num1)
                elif token == '/':
                    stack.append(num2 / num1)
        return int(stack.pop())