Skip to content

Practice Evaluate Reverse Polish Notation

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#150
LeetCode Problem

Evaluate Reverse Polish Notation

Problem Statement

Evaluate tokens as a valid reverse Polish expression and return its integer value. Operators are +, -, * and /; other tokens are integers. Each operator consumes the two preceding available operands in their original left-right order. Division truncates toward zero. Division by zero never occurs, and all intermediate values and the result fit signed 32-bit integers.

Source: Evaluate Reverse Polish Notation on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
tokens = ["2","1","+","3","*"]
Output
9

# Example 2

Input
tokens = ["4","13","5","/","+"]
Output
6

# Example 3

Input
tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
Output
22

Constraints

1 <= tokens.length <= 10^4
tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].

Related LeetCode Problems

Practice more problems similar to Evaluate Reverse Polish Notation.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.