Min Stack
I did this Leetcode problem. Here is my solution:
class MinStack(object): def __init__(self): self.stack = [] self.minstack = [] def push(self, val): """ :type val: int :rtype: None """ self.stack.append(val) self.minstack.append(min(val, self.minstack[-1] if self.minstack else val)) def pop(self): """ :rtype: None """ self.stack.pop() self.minstack.pop() def top(self): """ :rtype: int """ return self.stack[-1] def getMin(self): """ :rtype: int """ return self.minstack[-1] # Your MinStack object will be instantiated and called as such: # obj = MinStack() # obj.push(val) # obj.pop() # param_3 = obj.top() # param_4 = obj.getMin()