My LeetCode grinding. Trying to do a problem a day.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

problem.txt 521B

1234567891011121314151617181920
  1. Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
  2. push(x) -- Push element x onto stack.
  3. pop() -- Removes the element on top of the stack.
  4. top() -- Get the top element.
  5. getMin() -- Retrieve the minimum element in the stack.
  6. Example:
  7. MinStack minStack = new MinStack();
  8. minStack.push(-2);
  9. minStack.push(0);
  10. minStack.push(-3);
  11. minStack.getMin(); --> Returns -3.
  12. minStack.pop();
  13. minStack.top(); --> Returns 0.
  14. minStack.getMin(); --> Returns -2.