leetcode解题-evaluate reverse polish notation
描述
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /. Each operand may be an integer or another expression.
Some examples:
[“2”, “1”, “+”, “3”, “*“] -> ((2 + 1) * 3) -> 9
[“4”, “13”, “5”, “/“, “+”] -> (4 + (13 / 5)) -> 6
分析
逆波兰式求值,比较简单,注意代码里除法int(float(a) / b))
是因为Python 2有一个奇葩的设置就是除法结果是负数的时候是向下取整的(我们需要向0取整)。
代码
Python
1 | class (object): |