Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MinStack:
- def __init__(self):
- self.stack = []
- def push(self, val: int) -> None:
- if len(self.stack) > 0:
- self.stack.append([val, min(self.getMin(), val)])
- else:
- self.stack.append([val, val])
- def pop(self) -> None:
- self.stack.pop()
- def top(self) -> int:
- return self.stack[-1][0]
- def getMin(self) -> int:
- return self.stack[-1][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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement