150.|150. Evaluate Reverse Polish Notation

import operator class Solution(object): def evalRPN(self, tokens): """ :type tokens: List[str] :rtype: int """ stack=[] operators={"+":operator.add,"-":operator.sub,"*":operator.mul,"/":operator.div} for item in tokens: if item not in operators: stack.append(int(item)) else: b,a=stack.pop(),stack.pop() stack.append(int(operators[item](a*1.0,b))) return stack.pop()

    推荐阅读