986. Interval List Intersections 发表于 2022-01-03 1234567891011121314151617181920212223class Solution { public int[][] intervalIntersection(int[][] firstList, int[][] secondList) { List<int[]> list = new ArrayList<>(); int i = 0, j = 0; while (i < firstList.length && j < secondList.length) { if (firstList[i][1] < secondList[j][0]) { i++; } else if (secondList[j][1] < firstList[i][0]) { j++; } else { list.add(new int[]{Math.max(firstList[i][0], secondList[j][0]), Math.min(firstList[i][1], secondList[j][1])}); if (firstList[i][1] < secondList[j][1]) { i++; } else { j++; } } } return list.toArray(new int[0][]); }} Reference986. Interval List Intersections