150. Evaluate Reverse Polish Notation
problem description
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /. Each operand may be an integer or another expression.
Note:
Division between two integers should truncate toward zero. The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.
Example 1:
Example 2:
Example 3:
problem description
波兰表达式,直接使用一个栈解决,碰到数字压入,碰到符号就计算,并且将计算结果压入栈中
code
algorithm analysis
程序只需要线性时间遍历数组即可,时间复杂度O(n)
Last updated