/*
* function Interval(a, b){
* this.start = a || 0;
* this.end = b || 0;
* }
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param intervals Interval类一维数组
* @return Interval类一维数组
*/
function merge(intervals) {
if(intervals.length ===0) return [];
intervals.sort((a,b) => a.start -b.start);
let result = [intervals[0]];
for(let i= 1; i <intervals.length;i++){
let last = result[result.length -1];
let current = intervals[i];
if(current.start<= last.end){
last.end = Math.max(last.end,current.end);
}
else{
result.push(current);
}
}
return result;
}
module.exports = {
merge: merge,
};