Design a stack that supports push, pop, top, and getMin - all in O(1) time.
Implement the MinStack class:
MinStack() - initializes the stack.push(val) - pushes val onto the stack.pop() - removes the top element.top() - returns the top element without removing it.getMin() - returns the minimum element currently in the stack.Input: ["MinStack","push","push","push","getMin","pop","top","getMin"]
[[],[-2],[0],[-3],[],[],[],[]]
Output: [null,null,null,null,-3,null,0,-2]
Explanation: After pushing -2, 0, -3, the minimum is -3. After popping -3, top is 0 and minimum is -2.
pop, top, and getMin are always called on a non-empty stack.push(-2), push(0), push(-3), getMin, pop, top, getMin