Right or wrong ?????


  • 0
    Z

    Why it says last execute : push(512), push(-1024), push(-1024), push(512) ,pop, getMin, pop, getMin, pop, getMin;

    class MinStack {
        	int  *baseptr;
        	int *topptr;
        	int len;
        public:
        	 MinStack(void)
        	
    
    
    
    {
        		baseptr = new int;
        		len = 0;
        		topptr = baseptr + len;
        	}
            MinStack(int a)
        	{
        		len = a;
        		baseptr = new int;
        		topptr = baseptr + len;
        	}
        	void push(int x) {
        		topptr++;
        		*topptr = x;
        		len++;
        
        	}
        
        	void pop() {
        		topptr--;
        		len--;
        
        	}
        
        	int top() {
        		return(*topptr);
        	}
        
        	int getMin() {
        		int minele = *(baseptr+1);
        		for (int i = 1; i <= len; ++i)
        		{
        			if (*(baseptr + i)<minele)
        			{
        				minele = *(baseptr + i);
        			}
        		}
        		return(minele);
        	}
        };

  • 0
    H

    I encounter the same question as yours. And question below

    Input: push(-2),push(0),push(-1),getMin,top,pop,getMin
    Output: [-1024,-1024,-1024]
    Expected: [-2,-1,-2]


  • 0
    T

    Seems to have been fixed now. It might be printing out mismatched information.


Log in to reply
 

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