56.合并区间
class Solution {
public int[][] merge(int[][] intervals) {
Arrays.sort(intervals, (v1,v2)->v1[0]-v2[0]);
int n=intervals.length;
int[][] res=new int[n][2];
int id=-1;
for(int i=0;i<n;i++){
if(id==-1||intervals[i][0]>res[id][1]){
res[++id]=intervals[i];
}else{
res[id][1]=Math.max(res[id][1], intervals[i][1]);
}
}
return Arrays.copyOf(res, id+1);
}
}