Problem · Array
Evaluate Reverse Polish Notation
Learn this problemProblem statement
Evaluate an arithmetic expression in Reverse Polish Notation. Each operator consumes the two preceding values, and integer division truncates toward zero.
Function
evalRPN(tokens: String[]) → intExamples
Example 1
tokens = ["2","1","+","3","*"]return = 9Add 2 and 1, then multiply the result by 3.
Constraints
1 <= tokens.length <= 10000- Tokens are integers or one of
+,-,*,/. - The expression is valid and no division uses zero.