Evaluate Reverse Polish Notation

Problem Summary

(Write in your own words, not copied from LeetCode. This forces comprehension.)

Key Observations

(Patterns, constraints, or hints in the problem statement.)

Main Concepts Used

(Mark the CS concepts or algorithms used.)

Time & Space Complexity

Code

class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        stack = []

        for t in tokens:
            if t in ["+", "-", "*", "/"]:
                right = stack.pop()
                left = stack.pop()
                value = None
                if t == "+":
                    value = left + right
                elif t == "-":
                    value = left - right
                elif t == "*":
                    value = left * right
                else:
                    value = int(left / right)
                stack.append(value)
            else:
                stack.append(int(t))

        return stack[-1]

Common Mistakes / Things I Got Stuck On