# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param first int整型二维数组 # @param second int整型二维数组 # @return int整型二维数组 # class Solution: def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]: res = [] first, second = 0, 0 m = len(firstList) n = len(secondList) while first < m and second < n: # 找到a1,b1里面大的 left_max = max(firstList[first][0], secondList[second][0]) # 找到a2,b2里面小的 right_min = min(firstList[first][1], secondList[second][1]) # 大的和小的组成区间 if left_max <= right_min: res.append([left_max, right_min]) # b2 比 a2 小的时候,后面无效了 if secondList[second][1] < firstList[first][1]: second += 1 else: first += 1 return res