141. Min Stack
MediumStack
Design a stack that supports push, pop, top, and retrieving the minimum element, all in O(1) time complexity. Implement the MinStack class with these operations: push(val) pushes the element onto the stack, pop() removes the top element, top() returns the top element, and getMin() retrieves the minimum element in the stack.
Examples
Input: ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]]
Output: [null,null,null,null,-3,null,0,-2]
Explanation: Public test case for Min Stack
Constraints
- At most 3 * 10^4 calls will be made
Loading...
Run checks all cases above. Submit evaluates all test cases.