Would you please advise why this code does not work? Got runtime error...


  • 0
    G

    class MinStack {
    Stack<Integer> s = new Stack<Integer>();
    Stack<Integer> min = new Stack<Integer>();
    public void push(int x) {
    s.push(x);
    if(min.isEmpty()||min.peek()>=x) min.push(x);
    }

    public void pop() {
        if(s.peek()==min.peek()) min.pop();
        s.pop();
    }
    
    public int top() {
        return s.peek();
    }
    
    public int getMin() {
        return min.peek();
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.