Min Stack
Easy
Stacks
Stack
Design
Design a stack that supports push, pop, top, and getMin in O(1) time.
Constraints
Methods ≤ 3×10^4
Examples
Example 1:
Input: push -2
push 0
push -3
getMin
pop
top
getMin
Output: -3
0
-2
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console