LeetCode 150 Evaluate Reverse Polish Notation - Solution

The core idea

Use a stack of numbers. Scan left to right.

If you see a number, push it onto the stack.

If you see an operator, pop two numbers, apply the operator, and push the result back.

The second-to-top number is the left operand, the top is the right operand. This matters for subtraction and division.

At the end, the stack contains exactly one number: the answer.