思路:
class Solution {public int[][] merge(int[][] intervals) {if(intervals.length <= 1) return intervals;List<int[]> res = new ArrayList<>();Arrays.sort(intervals, (o1,o2) -> o1[0] - o2[0]);for(int[] interval : intervals){if(res.size() == 0 || interval[0] > res.get(res.size()- 1)[1]){res.add(interval);}else{res.get(res.size()- 1)[1] = Math.max(res.get(res.size()- 1)[1],interval[1]);}}return res.toArray(new int[res.size()][1]);}
}