Evaluate Reverse Polish Notation
Evaluate an arithmetic expression written in postfix order with a stack.
The problem
Implement Solution.evalRPN(tokens). tokens is an arithmetic expression in Reverse Polish Notation: each operator comes after its two operands. Every token is either an integer written as a string, such as "-3", or one of "+", "-", "*" and "/". Return the value of the expression as an integer. Division between two integers truncates toward zero, so 8 / -3 is -2. For example, ["2", "1", "+", "3", "*"] means (2 + 1) * 3, which is 9. The expression is always valid, never divides by zero, and every intermediate value fits in a 32-bit signed integer.
Starter code
class Solution:
def evalRPN(self, tokens):
passPublic examples
tokens = ["2", "1", "+", "3", "*"]gives9tokens = ["5", "2", "-"]gives3tokens = ["8", "-3", "/"]gives-2
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
