class MinStack:
def __init__(self):
self.stack = []
self.min_stack = []
def push(self, value: int) -> None:
self.stack.append(value)
if not self.min_stack or value <= self.min_stack[-1]:
self.min_stack.append(value)
def pop(self) -> None:
if not self.stack:
raise ValueError("empty stack")
if self.stack[-1] == self.min_stack[-1]:
self.min_stack.pop(-1)
self.stack.pop(-1)
def top(self) -> int:
if not self.stack:
raise ValueError("empty stack")
return self.stack[-1]
def getMin(self) -> int:
return self.min_stack[-1]
# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(value)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()