Problem · Array

Evaluate Reverse Polish Notation

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem statement

Evaluate an arithmetic expression in Reverse Polish Notation. Each operator consumes the two preceding values, and integer division truncates toward zero.

Function

evalRPN(tokens: String[]) → int

Examples

Example 1

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

Add 2 and 1, then multiply the result by 3.

Constraints

  • 1 <= tokens.length <= 10000
  • Tokens are integers or one of +, -, *, /.
  • The expression is valid and no division uses zero.

More Atlassian problems

drafts saved locally
public int evalRPN(String[] tokens) {
  // Write your code here.
}
tokens["2","1","+","3","*"]
expected9
checking account