-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path495.py
33 lines (31 loc) · 1.24 KB
/
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
28
29
30
31
32
33
__________________________________________________________________________________________________
sample 264 ms submission
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
if not timeSeries:
return 0
total_duration = 0
current_end = timeSeries[0]
for attack in timeSeries:
attack_end = attack + duration
if attack > current_end:
total_duration += duration
else:
total_duration += attack_end - current_end
current_end = attack_end
return total_duration
__________________________________________________________________________________________________
sample 268 ms submission
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
res = 0
if not timeSeries: return 0
prev = timeSeries[0]
for value in timeSeries[1:]:
if value > prev+duration:
res += duration
else:
res += value-prev
prev = value
return res+duration
__________________________________________________________________________________________________