-
Notifications
You must be signed in to change notification settings - Fork 19
/
answer.py
31 lines (25 loc) · 868 Bytes
/
answer.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
28
29
30
31
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
class Solution:
def findPoisonedDuration(self, timeSeries, duration):
"""
:type timeSeries: List[int]
:type duration: int
:rtype: int
"""
if len(timeSeries) == 0:
return 0
elif len(timeSeries) == 1:
return duration
time = 0
# Loop through each attack and add the appropriate duration
for i in range(len(timeSeries)-1):
diff = timeSeries[i+1] - timeSeries[i]
if diff < duration:
time += diff
else:
time += duration
# Add last attack
time += duration
return time
#-------------------------------------------------------------------------------