495. 提莫攻击
为保证权益,题目请参考 495. 提莫攻击(From LeetCode).
解决方案1
Python
python
# 495. 提莫攻击
# https://leetcode-cn.com/problems/teemo-attacking/
################################################################################
from typing import List
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
if len(timeSeries) ==0:
return 0
lastTime = timeSeries[0]
cou = duration
for i in range(1, len(timeSeries)):
if timeSeries[i] < lastTime + duration:
cou -= lastTime + duration - timeSeries[i]
cou += duration
lastTime = timeSeries[i]
return cou
################################################################################
if __name__ == '__main__':
solution = Solution()
print(solution.findPoisonedDuration([1,2,3,4,5], 5))
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
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