LeetCode 495
使用一个中毒的时间段列表来记录,如果新的攻击的开始时间敌人已经处于中毒状态,那么只改变中毒结束的时间。每次的结果都先加入到结果的时间段列表。最后做一下统计
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
result = []
for t in timeSeries:
if result and result[-1][1] >= t:
result[-1][1] = t+duration
else:
result.append([t, t+duration])
total = sum(r[1]-r[0] for r in result)
return total