#155 - Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element, all in O(1) time.
push(val)– pushes the element onto the stack.pop()– removes the element on top of the stack.top()– gets the top element.getMin()– retrieves the minimum element in the stack.
| Input | Output |
|---|---|
Operations | Output |
push(-2), push(0), push(-3), getMin(), pop(), top(), getMin() | [null,null,null,-3,null,0,-2] |