-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_495.py
30 lines (24 loc) · 877 Bytes
/
array_495.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def findPoisonedDuration(self, timeSeries, duration):
"""
:type timeSeries: List[int]
:type duration: int
:rtype: int
"""
if len(timeSeries) <= 0 or duration <= 0:
return 0
active_time = 0
start_time = timeSeries[0]
end_time = start_time + duration
for i in range(1, len(timeSeries)):
if end_time <= timeSeries[i]:
active_time += end_time - start_time
start_time = timeSeries[i]
end_time = timeSeries[i] + duration
elif end_time <= timeSeries[i] + duration:
end_time = timeSeries[i] + duration
active_time += end_time - start_time
return active_time
if __name__ == '__main__':
solution = Solution()
print(solution.findPoisonedDuration([1, 2], 2))