标签:tin solution 执行 color 表达式求值 obj list etc app
class Solution(object): def evalRPN(self, tokens): """ :type tokens: List[str] :rtype: int """ stack=[] for i in tokens: if i not in ‘+-*/‘: stack.append(i) else: a=stack.pop() b=stack.pop() if i==‘+‘: c=int(a)+int(b) stack.append(c) if i==‘-‘: c = int(b) - int(a) stack.append(c) if i==‘*‘: c = int(a) * int(b) stack.append(c) if i==‘/‘: c = int(b) / int(a) if int(a)*int(b)<0 and int(b)!=c*int(a): c=c+1 stack.append(c) return stack.pop()
标签:tin solution 执行 color 表达式求值 obj list etc app
原文地址:https://www.cnblogs.com/taoyuxin/p/11782379.html