Stack Min
Design a stack that, in addition to push and pop, has a function min which returns the minimum element.
Push, pop and min should all operate in O(1) time.
Example:
s = MinStack()
s.push(5)
s.push(3)
s.push(7)
s.min() # → 3
s.pop() # removes 7
s.pop() # removes 3
s.min() # → 5
Hints
solution.py
Python ready
Test Output
▶
Click "Run Tests" to execute your code