Reverse Polish Calculator
L5 Medium Stack
Reverse Polish notation puts operators after their operands, which is exactly what a stack evaluates naturally: push numbers, apply operators to the top two.
Given an array of strings tokens formed from integers and the operators +, -, *, / in Reverse Polish notation, evaluate it and return the resulting integer. Division truncates toward zero.
Examples
▸ tokens = ["2", "1", "+", "3", "*"]
→ 9
▸ tokens = ["4", "13", "5", "/", "+"]
→ 6
▸ tokens = ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
→ 22