添加0150逆波兰表达式求值 python3 版本

This commit is contained in:
boom-jumper
2021-05-27 20:37:53 +08:00
committed by GitHub
parent 597f24d2a0
commit 0ae9d1808c

View File

@ -224,6 +224,22 @@ var evalRPN = function(tokens) {
};
```
python3
```python
def evalRPN(tokens) -> int:
stack = list()
for i in range(len(tokens)):
if tokens[i] not in ["+", "-", "*", "/"]:
stack.append(tokens[i])
else:
tmp1 = stack.pop()
tmp2 = stack.pop()
res = eval(tmp2+tokens[i]+tmp1)
stack.append(str(int(res)))
return stack[-1]
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)