https://leetcode.com/problems/evaluate-reverse-polish-notation/
堆栈
class Solution:
# @param {string[]} tokens
# @return {integer}
def evalRPN(self, tokens):
list=[]
for i in tokens:
sign=['+','-','*','/']
if i not in sign:
list.append(i)
else:
temp2=int(list.pop(-1))
temp1=int(list.pop(-1))
temp3=0
#结果还要入栈
if i=='+':
temp3=temp1+temp2
elif i=='-':
temp3=temp1-temp2
elif i=='*':
temp3=temp1*temp2
else:
if temp1*temp2>0:
temp3=abs(temp1)/abs(temp2)
else:
temp3=abs(temp1)/abs(temp2)*-1
list.append(temp3)
return int(list[0])