def Intersection(p1, p2):
answer = []
i = j = 0
while i < len(p1) and j < len(p2):
if p1[i] == p2[j]:
answer.append(p1[i])
i += 1
j += 1
elif p1[i] > p2[j]:
j += 1
else:
i += 1
return answer
L1 = [13, 57, 61, 114, 987, 1000]
L2 = [5, 23, 57, 63, 114, 257, 1000]
L3 = [57, 114, 120]
L13 = Intersection(L1, L3)
Intersection(L13, L2)
[57, 114]
首先intersect长度最短的两个, 然后再和第三个合并
转载请注明原文地址:https://blackberry.8miu.com/read-14287.html