My LeetCode grinding. Trying to do a problem a day.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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.