Why my code get "Output Limit Exceeded" error?


  • 0
    T

    The code below passed VC IDE and all my test cases. But OJ complained "Output Limit Exceeded".
    Please help if anyone know how.
    Thank you.

    class Solution {
    public:
        vector<Interval> insert(vector<Interval> &intervals, Interval newInterval) {
            int i=-1,N=intervals.size();
            vector<Interval> viv;
            if(N==0)
            {
                viv.push_back(newInterval);
                return viv;
            }
            while(i+1<N && intervals[i+1].start<=newInterval.start)
            {
                i++;
                viv.push_back(intervals[i]);
            }
            bool gluelefttoi=(i>-1 && intervals[i].end-1+1>=newInterval.start);    
            if(gluelefttoi)
                viv.back().end=newInterval.end;
            else
                viv.push_back(newInterval);
            int j=i;
            while(j<N && intervals[j].end-1<newInterval.end-1)
                j++;
            bool gluerighttoj=(j<N && intervals[j].start-1<=newInterval.end-1);
            int of=0;
            if(gluerighttoj)
            {
                viv.back().end=intervals[j].end;
                of=1;
            }
            for(int k=j+of;k<N;k++)
                viv.push_back(intervals[k]);
            return viv;       
        }
    };

Log in to reply
 

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