We’re preparing your current view and syncing the latest data.
Given an array of strings tokens that represents an arithmetic expression in Reverse Polish Notation, evaluate the expression and return the value. Valid operators are '+', '-', '*', and '/'. Each operand may be an integer or another expression. Note that division between two integers should truncate toward zero.
An array of strings tokens, where each element is either an integer or one of the four operators: '+', '-', '*', '/'.
An integer representing the evaluated value of the expression.
1 <= tokens.length <= 10^4; tokens[i] is either an operator or an integer in the range [-200, 200].
Example 1
Input
2,1,+,3,*
Output
9
Explanation
Expression evaluates to ((2 + 1) * 3) = 9
Example 2
Input
4,13,5,/,+
Output
6
Explanation
Expression evaluates to (4 + (13 / 5)) = 6
Example 3
Input
10,6,9,3,+,-11,*,/,*,17,+,5,+
Output
22
Explanation
Expression evaluates to 22