Problem
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +
, -
, *
, /
. Each operand may be an integer or another expression.
Examples
1 | Input: ["2", "1", "+", "3", "*"] |
1 | Input: ["4", "13", "5", "/", "+"] |
1 | Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"] |
Boundary Conditions
- Will there be any divided by zero operation?
- Can the given RPN expression be wrong?
- Not matched
- Expression includes invalid characters
Solution
Method:
Time Complexity:
Space Complexity:
1 | class Solution: |
or
1 | class Solution: |