248. Implement a Min Stack
Medium · Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time O(1).
Examples
Example 1 Input: push(-2); push(0); push(-3); getMin()→-3; pop(); top()→0; getMin()→-2 Output: [-3, 0, -2]
Constraints
- -2³¹ ≤ val ≤ 2³¹-1, at most 3×10⁴ calls