986. Interval List Intersections (Medium) - TengnanYao/daily_leetcode GitHub Wiki
class Solution(object):
def intervalIntersection(self, firstList, secondList):
"""
:type firstList: List[List[int]]
:type secondList: List[List[int]]
:rtype: List[List[int]]
"""
result = []
i = j = 0
n1, n2 = len(firstList), len(secondList)
while i < n1 and j < n2:
a0, a1 = firstList[i]
b0, b1 = secondList[j]
if a0 <= b1 and b0 <= a1:
result.append([max(a0, b0), min(a1, b1)])
if a1 >= b1:
j += 1
else:
i += 1
return result