js solution.


  • 0
    N
    var merge = function(intervals) {
        intervals.sort(function(a, b){
           return a.start - b.start; 
        });
        var ans = new Array();
        var i = 0;
        while(i < intervals.length){
            var itv = new Interval(intervals[i].start, intervals[i].end);
            while(++i < intervals.length && intervals[i].start <= itv.end){
                itv.end = intervals[i].end > itv.end? intervals[i].end : itv.end;
            }
            ans.push(itv);
        }
        return ans;
    };
    

Log in to reply
 

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