Very short and easy to understand C++ solution
vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {\n        vector<Interval> ret;\n        auto it = intervals.begin();\n        for(;
    vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {\n        vector<Interval> ret;\n        auto it = intervals.begin();\n        for(; it!=intervals.end(); ++it){\n\t\t\tif(newInterval.end < (*it).start) //all intervals after will not overlap with the newInterval\n\t\t\t\tbreak; \n\t\t\telse if(newInterval.start > (*it).end) //*it will not overlap with the newInterval\n\t\t\t\tret.push_back(*it); \n            else{ //update newInterval bacause *it overlap with the newInterval\n                newInterval.start = min(newInterval.start, (*it).start);\n                newInterval.end = max(newInterval.end, (*it).end);\n            }\t\n        }\n        // don't forget the rest of the intervals and the newInterval\n\t\tret.push_back(newInterval);\n\t\tfor(; it!=intervals.end(); ++it)\n\t\t\tret.push_back(*it);\n\t\treturn ret;\n    }\nMy question is why this code need 500ms !?
[]