leetcode 150. Evaluate Reverse Polish Notation 发表于 2018-10-29 | 分类于 leetcode 题目链接 思路:逆波兰用栈来做 1234567891011121314151617181920212223242526class Solution: def evalRPN(self, tokens): """ :type tokens: List[str] :rtype: int """ stack = [] for token in tokens: if token in '+-*/': num2 = stack.pop() num1 = stack.pop() if token == '+': num = int(num1)+int(num2) stack.append(str(num)) elif token == '-': num = int(num1)-int(num2) stack.append(str(num)) elif token == '*': num = int(num1)*int(num2) stack.append(str(num)) else: num = int(int(num1)/int(num2)) stack.append(str(num)) else: stack.append(token) return int(stack[0])