bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 155. Min Stack

155. Min Stack

Leetcode Solutions

Approach: Stack of Value/Minimum Pairs

  1. Initialize a stack to store pairs of (value, current minimum).
  2. On push, insert a pair of the value and the current minimum into the stack.
  3. On pop, remove the top element from the stack.
  4. On top, return the first element of the pair at the top of the stack.
  5. On getMin, return the second element of the pair at the top of the stack.
UML Thumbnail

Approach: Two Stacks

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR