Skip to content

#155 - Min Stack

MediumStack
Open on LeetCode

Design a stack that supports push, pop, top, and retrieving the minimum element, all in O(1) time.

  • push(val) – pushes the element onto the stack.
  • pop() – removes the element on top of the stack.
  • top() – gets the top element.
  • getMin() – retrieves the minimum element in the stack.
InputOutput
OperationsOutput
push(-2), push(0), push(-3), getMin(), pop(), top(), getMin()[null,null,null,-3,null,0,-2]

Released under the MIT License.