python

Python: Stack with Push, Pop and seek Minimum Value with O(1)

Pyhton 3 code to implement a stack with push, pop and seekMin function with time complexity of O(1) class Stack: def __init__(self): self.items = [] self.minList = [] self.min = None   def push(self, item): print("Push: ", item) self.items.append(item) if not self.min: self.min = item else: if item <= self.min: self.minList.append(self.min) self.min = item