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
The code is supposed to run through the two arrays and find the max overlap give a list such as [(5,15), (18,25), (3,12), (4, 11), (1,15), (18,19)]
in the given time ( T
). Running this code is giving me a tuple index error. I can't seem to figure out why it is giving me an index error.
如果T
大于interval_lst
的长度,则i
和/或j
可以达到该长度,但是startArr
和endArr
中的那个索引处都没有元素(因为它们的长度与interval_lst
相同)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.