Evaluate Reverse Polish Notation
Problem Evaluate an arithmetic expression given in Reverse Polish Notation (postfix). Tokens are integers and the operators +, -, *, /. Each operator applies to the two most recent operands.
Input / Output
- Input: a list of string tokens in RPN.
- Output: the integer result of evaluating the expression.
Constraints
- The expression is valid.
- Division truncates toward zero (clarify).
- Operands and intermediate results fit in a 64-bit integer.
Example
- ["2","1","+","3","*"] -> 9 ((2+1)*3)
- ["4","13","5","/","+"] -> 6 (4 + 13/5)
added …