Download Evaluate Reverse Polish Notation.py
class Solution(object): def evalRPN(self, tokens): """ :type tokens: List[str] :rtype: int """ stack =  for t in tokens: try: temp = int(t) stack.append(temp) except: b = stack.pop() a = stack.pop() if t == "+": a += b elif t == "-": a -= b elif t == "*": a *= b else: a = int(a * 1.0 / b) stack.append(a) return stack[-1]
Leetcode 150 Evaluate Reverse Polish Notation problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.