Where's the bug?


  • 0
    J
    public class MinStack {
    
    /** initialize your data structure here. */
    Stack stack;
    Stack min;
    
    int minv; 
    public MinStack() {
        minv = Integer.MAX_VALUE;
        stack = new Stack();
        min = new Stack();
    }
    
    public void push(int x) {
        minv = Math.min(minv, x);
        min.push(minv);
        stack.push(x);
    }
    
    public void pop() {
        stack.pop();
        min.pop();
    }
    
    public int top() {
        return (int)stack.peek();
    }
    
    public int getMin() {
        return (int)min.peek();
    }
    

    }


Log in to reply
 

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