Evaluate Reverse Polish Notation
Problem Statement
Given the Reverse Polish Notation (RPN) of an arithmetic expression as an array of strings, evaluate the expression.
Reverse Polish Notation is a mathematical notation where operators follow their operands. The expression is evaluated by applying the operators from left to right.
Input Constraints
- The input will be an array of strings and , representing the arithmetic expression in Reverse Polish Notation.
- The input will only contain the four basic arithmetic operators: , , , .
- The input will not contain any invalid characters or invalid operations.
- The input will only contain positive integers as operands.
- The input will always form a valid arithmetic expression.
Output Constraints
- The function should return the result of the arithmetic expression as a floating-point number.
- The result should be accurate up to four decimal places.
Time and Space Complexity
- The function should have a time complexity of O(n), where n is the number of operations in the input array.
- The function should have a space complexity of O(n), where n is the number of operations in the input array.
Assumptions
- The input will always contain a valid stack-based RPN expression.
- The input will never contain any invalid characters or invalid operations.
Example
Input: {"tokens":["2","1","+","3","*"]}
Output: 9