algorythms
Stack
LC #150Medium

Evaluate Reverse Polish Notation

Stack

Problem

Evaluate the value of an arithmetic expression in Reverse Polish Notation (postfix).

arraymathstack

Constraints

  • 1 ≤ tokens.length ≤ 10⁴
  • tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in [-200, 200].

Example

Inputtokens = ["2", "1", "+", "3", "*"]
Output9
Why

((2 + 1) * 3) = 9

Hints — reveal one at a time