Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
public class MinStack {
private Stack<(int val, int min)> stack = new();
public void Push(int val) {
// TODO: implement your solution here
}
public void Pop() {
// TODO: implement your solution here
}
public int Top() {
// TODO: implement your solution here
return 0;
}
public int GetMin() {
// TODO: implement your solution here
return 0;
}
}MinStack minStack = new MinStack(); minStack.Push(-2); minStack.Push(0); minStack.Push(-3); minStack.GetMin(); // return -3 minStack.Pop(); minStack.Top(); // return 0 minStack.GetMin(); // return -2null