Evaluate Reverse Polish Notation

Given a list of tokens representing an arithmetic expression in Reverse Polish Notation (postfix notation), evaluate the expression and return the result. The valid operators are +, -, *, and /, and division should truncate toward zero.

Input Format

tokens = array of tokens in postfix (Reverse Polish) notation

Output Format

integer result of the expression

Constraints

Examples

Example 1:

Input:

tokens = ["2","1","+","3","*"]

Output:

9

Explanation:

((2 + 1) * 3) = 9

Example 2:

Input:

tokens = ["4","13","5","/","+"]

Output:

6

Explanation:

((13 / 5) + 4) = 6

Loading...
Evaluate Reverse Polish Notation - Stack