Object-Oriented Programming · ByteDance · Medium
Implement a MinStack class that behaves as a last-in, first-out container and can also report the smallest value currently stored in it. The class must expose push, pop, top, and getMin, and every one of these operations has to complete in constant time. MinStack() — initializes an empty stack. void push(int val) — puts val on top of the stack. void pop() — removes and discards the top element. int top() — returns the top value without removing it. int getMin() — returns the…
Checking your access…