classSolution{publicint[][]merge(int[][] intervals){List<int[]> res =newArrayList<>();Arrays.sort(intervals,(a, b)-> a[0]- b[0]);res.add(intervals[0]);for(int i =1; i < intervals.length; i++){int[] cur = intervals[i];int[] pre = res.get(res.size()-1);//res里的最后一个元素if(cur[0]> pre[1]){res.add(cur);}else{pre[1]=Math.max(cur[1], pre[1]);// !! 取最大的右边界}}return res.toArray(newint[res.size()][]);//将集合(ArrayList动态数组)转化为二维数组}}