Calculator 2018-11-23 Algorithms stack, topic Catalogue 1. 150. Evaluate Reverse Polish Notation 150. Evaluate Reverse Polish Notation Stack, Reverse Polish Notation 123456789101112131415161718192021class Solution(object): def evalRPN(self, tokens): stack = [] for token in tokens: if token in "+-*/": n2 = stack.pop() n1 = stack.pop() if token == '+': temp = n1 + n2 elif token == '-': temp = n1 - n2 elif token == '*': temp = n1 * n2 else: temp = n1 / n2 if n1 * n2 < 0 and n1 % n2 != 0: temp += 1 stack.append(temp) else: stack.append(int(token)) return stack.pop() Newer DP - Sequence Adjacent Element Older Serialization