def max_logged_in(interval_lst,T):
startArr, endArr = zip(*interval_lst)
i = 0
j = 0
maxOverlap = 0
currentOverlap = 0
while (i<T and j<T):
if (startArr[i] < endArr[j]):
currentOverlap = currentOverlap + 1
maxOverlap = max(maxOverlap, currentOverlap)
i = i + 1
else:
currentOverlap = currentOverlap - 1
j = j + 1
代码应该通过两个数组运行,并找到最大重叠在给定时间内给出一个列表,例如[(5,15), (18,25), (3,12), (4, 11), (1,15), (18,19)]
(T
)。
运行此代码给我一个元组索引错误。我似乎无法弄清楚它为什么会给我一个索引错误。
答案 0 :(得分:1)
如果T
大于interval_lst
的长度,则i
和/或j
可以达到该长度,但任何一个都没有元素该索引处startArr
或endArr
(因为它们的长度与interval_lst
相同)。