Min Stack w Python
class MinStack:
def __init__(self):
self.stack=deque([])
self.min=deque([])
def push(self, val: int) -> None:
self.stack.append(val)
if len(self.min)==0 or val<self.min[-1]:
self.min.append(val)
else:
self.min.append(self.min[-1])
def pop(self) -> None:
x=self.stack.pop()
self.min.pop()
return x
def top(self) -> int:
return self.stack[-1]
def getMin(self) -> int:
return self.min[-1]
Hacker Harsha