Evaluate Reverse Polish Notation
Problem Evaluate an arithmetic expression given in Reverse Polish (postfix) Notation. Tokens are integers and the operators +, −, *, /. Division truncates toward zero.
Input / Output
- Input: array of string tokens in RPN.
- Output: the integer result of evaluating the expression.
Constraints
- The expression is always valid.
- Operands and intermediate results fit in a 32-bit integer; division truncates toward zero.
Example
- ["2","1","+","3","*"] -> 9 ((2+1)*3)
- ["4","13","5","/","+"] -> 6 (4 + 13/5)
added …