Min Stack
class MinStack:
def __init__(self):
self.stk = []
self.mstk = [float('inf')]
def push(self, val: int) -> None:
if self.mstk[-1] >= val:
self.mstk.append(val)
self.stk.append(val)
def pop(self) -> None:
temp = self.stk.pop()
if self.mstk[-1] == temp:
self.mstk.pop()
def top(self) -> int:
return self.stk[-1]
def getMin(self) -> int:
return self.mstk[-1]