Why MLE? I write in java using linkedlist


  • 0
    X

    As the title says, I got a MLE with the following code, but I don't understand why.
    Any help?

    class MinStack {
    private LinkedList<Integer> ll = new LinkedList<Integer>();
    private int min = Integer.MIN_VALUE;
    public void push(int x) {
    	if(min > x)
    		min = x;
        ll.add(0, x);
    }
    
    public void pop() {
    	if(ll.size() == 0)
    		return;
        int x = ll.remove(0);
        if(ll.size() == 0)
        	min = Integer.MIN_VALUE;
        else if(x == min)
        {
        	int tm = ll.get(0);
        	for(int t : ll)
        	{
        		if(tm > t)
        			tm = t;
        	}
        	min = tm;
        }
    }
    
    public int top() {
    	if(ll.size() == 0)
    		return -1;
        return ll.get(0);
    }
    
    public int getMin() {
        return min;
    }
    

    }


Log in to reply
 

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