986. 區間列表的交集
阿新 • • 發佈:2019-02-03
{} result 交集 區間 end lengthb update sel sta
# Definition for an interval.
# class Interval(object):
# def __init__(self, s=0, e=0):
# self.start = s
# self.end = e
class Solution(object):
def intervalIntersection(self, A, B):
"""
:type A: List[Interval]
:type B: List[Interval]
:rtype: List[Interval]"""
lengthA=len(A)
lengthB=len(B)
resultA={}
resultB={}
for i in range(0,lengthA):
start=A[i][0]
end=A[i][1]
resultA.update({start:(i,0)})
resultA.update({end: (i,1)})
for i in range(0,lengthB):
start=B[i][0]end=B[i][1]
resultB.update({start:(i,0)})
resultB.update({end: (i,1)})
print resultA,resultB
for i in resultA.keys():
for j in resultB.keys():
print Solution().intervalIntersection( [[0,2],[5,10],[13,23],[24,25]],[[1,5],[8,12],[15,24],[25,26]])
986. 區間列表的交集