classMinStack{private Stack<Integer> s1;private Stack<Integer> s2;privateint k = Integer.MAX_VALUE;/** initialize your data structure here. */publicMinStack(){
s1 =newStack<>();
s2 =newStack<>();}publicvoidpush(int x){
s1.add(x);
k = Math.min(k,x);
s2.add(k);}publicvoidpop(){
s1.pop()
s2.pop();
k = s2.isEmpty()? Integer.MAX_VALUE : s2.peek();}/**
public void pop() {
if(stack.pop().equals(min_stack.peek()))
min_stack.pop();
}
**/publicinttop(){return s1.peek();}publicintgetMin(){return s2.peek();}}/**
* Your MinStack object will be instantiated and called as such:
* MinStack obj = new MinStack();
* obj.push(x);
* obj.pop();
* int param_3 = obj.top();
* int param_4 = obj.getMin();
*/