Skip to main content
Back to problems
Leetcode
Medium
Stacks
Arrays
Math
Evaluate Reverse Polish Notation

Evaluate an arithmetic expression written in Reverse Polish Notation (postfix form).

Acceptance 100%
Problem Statement

Evaluate Reverse Polish Notation

You are given an arithmetic expression in Reverse Polish Notation (RPN). In this notation, every operator follows its operands.

Your task is to evaluate the expression and return the final integer result.

Supported operators:

  • + : addition
  • - : subtraction
  • * : multiplication
  • / : integer division that truncates toward zero

Assume the input expression is valid and there is exactly one final result.

Input Format

  • A list of tokens representing an RPN expression.
  • Each token is either:
    • an integer, or
    • one of +, -, *, /.

Output Format

Return a single integer: the value of the expression.

Constraints

  • The expression is valid.
  • Division truncates toward zero.
  • Intermediate and final values fit in standard 32-bit signed integer range for interview purposes.
Examples
Sample cases returned by the problem API.

Example 1

Input

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

Output

9

Explanation

First compute 2 + 1 = 3, then 3 * 3 = 9.

Example 2

Input

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

Output

6

Explanation

First compute 13 / 5 = 2, then 4 + 2 = 6.

Show 1 more example

Example 3

Input

["10","6","9","3","+","-11","*","/","*","17","+","5","+"]

Output

22

Explanation

Evaluate the expression left to right using a stack of operands.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.