What is wrong with my pop method ? why it is not working correctly


#1
class Solution {
    
    Stack<Integer> a = new Stack<>();
    Stack<Integer> min = new Stack<>();
    
    Solution(){
        a = new Stack<>();
        min = new Stack<>();
    }
    
    public void push(int x) {
        a.push(x);    
        if(min.isEmpty() || x <= min.peek())
            min.push(x);
      //  System.out.println("push "+a);
    }

    public void pop() {
        if(!a.isEmpty()){
            if(a.peek() == min.peek()){
                a.pop();
                min.pop();
            }else{
                a.pop();
            }
        }
    }

    public int top() {
        if(a.isEmpty()){
            return -1;
        }
        //System.out.println("top "+a);
        return a.peek();
    }

    public int getMin() {
        if(min.isEmpty()){
            return -1;
        }
       // System.out.println("min "+a+"  "+min);
        return min.peek();
    }
    
}