← All problems

Evaluate Reverse Polish Notation

medium

Evaluate an arithmetic expression given in Reverse Polish Notation, as an array of string tokens. Operands can be integers, operators are +, -, *, / — division truncates toward zero. Return the result.

Example

Input: tokens = ["2", "1", "+", "3", "*"]
Output: 9        // (2 + 1) * 3
Loading...