Elegant C++ STL solution, using "equal_range" to find overlapped intervals.
class Solution {\n    public:\n        vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {\n            auto compare = [] (const Interv
    class Solution {\n    public:\n        vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {\n            auto compare = [] (const Interval &intv1, const Interval &intv2)\n                              { return intv1.end < intv2.start; };\n            auto range = equal_range(intervals.begin(), intervals.end(), newInterval, compare);\n            auto itr1 = range.first, itr2 = range.second;\n            if (itr1 == itr2) {\n                intervals.insert(itr1, newInterval);\n            } else {\n                itr2--;\n                itr2->start = min(newInterval.start, itr1->start);\n                itr2->end = max(newInterval.end, itr2->end);\n                intervals.erase(itr1, itr2);\n            }\n            return intervals;\n        }\n    };
[]