【sort】57. Insert Interval

将intervals的元素按照start从小到大的顺序排序,并将有重叠区域的相邻元素融合;

/**
 * Definition for an interval.
 * struct Interval {
 *     int start;
 *     int end;
 *     Interval() : start(0), end(0) {}
 *     Interval(int s, int e) : start(s), end(e) {}
 * };
 */
class Solution {
public:
    vector insert(vector& intervals, Interval newInterval) {
        vector res;
        intervals.push_back(newInterval);
        sort(intervals.begin(),intervals.end(),cmp); //sort the intervals elements according to the start time
        
        int num=0;
        res.push_back(intervals[num]);
        for(int i =1;i=intervals[i].start)
            {
                if(res[num].end

 

你可能感兴趣的:(LeetCodeView)