Description
给定两个interval序列,输出所有intersection interval
Solution
T O(N)
class Solution:
def intervalIntersection(self, A: List[List[int]], B: List[List[int]]) -> List[List[int]]:
startA = 0
startB = 0
interval = []
while startA < len(A) and startB < len(B):
if A[startA][1] < B[startB][0]:
startA+=1
elif A[startA][0] > B[startB][1]:
startB +=1
else:
interval.append([max(A[startA][0],B[startB][0]),min(A[startA][1],B[startB][1])])
if A[startA][1]>B[startB][1]:
startB+=1
elif A[startA]==B[startB]:
startA+=1
startB+=1
else:
startA+=1
return interval
网友评论