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