My solution 11lines C++


  • 0
    A

    vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {
    int i;
    for(i=0;i<intervals.size();i++) if(newInterval.start<intervals[i].start) break;
    intervals.insert(intervals.begin()+i,newInterval);
    for(int i=0;i<intervals.size()-1;i++) {
    if(intervals[i].end>=intervals[i+1].start) {
    intervals[i].end=max(intervals[i].end, intervals[i+1].end);
    intervals.erase(intervals.begin()+i+1);
    i--;
    }
    }
    return intervals;
    }


Log in to reply
 

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