不停code不停想-7行代码解决问题


  • 0
    I

    不停code不停想-7行代码解决问题
    vector<Interval> merge(vector<Interval>& intervals) {
    vector<Interval> VEC;
    sort(intervals.begin(), intervals.end(), [](Interval a, Interval b){return a.start < b.start; });
    for (auto it = intervals.begin(); it != intervals.end();){
    int start = (*it).start, end = it++->end;
    while (it < intervals.end() && end >= it->start) end = max(end, (it++)->end);
    VEC.push_back(Interval(start, end));}
    return VEC;
    }


Log in to reply
 

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