Help!!the code has problem with "Output Limit Exceeded",what`s wrong with it?


  • 0
    T
    #define SIZE 10
    class MinStack {
    private:
        int count;
        int* curr;
        int* first;
        int* pmin;
        int* min;
    public:
        MinStack(){
            first = new int[SIZE];
            pmin = new int[SIZE];
            curr = first;
            count = 0;
            min = pmin;
            *min=65536;
        }
        ~ MinStack(){
            delete[] first;
            delete[] pmin;
        }
        void push(int x) {
           if(count<SIZE){
                    if(x <= *min){
                            min++;
                            *min=x;
                    }
                    *curr = x;
                    curr++;
                    count++;
            }
        }
    
        void pop() {
            if(count > 1){
                    curr--;
                    count--;
                    if(*curr == *min){
                            min--;
                    }
            }
        }
    
        int top() {
            return *(curr-1);
        }
    
        int getMin() {
            *(min);
        }
    };

Log in to reply
 

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