Leetcode 495. Teemo Attacking

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Teemo Attacking

2. Solution

解析:按顺序计算提莫的毒性伤害时间即可。

  • Version 1
1
2
3
4
5
6
7
8
9
10
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
count = duration
n = len(timeSeries)
for i in range(n-1):
if timeSeries[i] + duration <= timeSeries[i+1]:
count += duration
else:
count += timeSeries[i+1] - timeSeries[i]
return count
  • Version 2
1
2
3
4
5
6
7
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
count = duration
n = len(timeSeries)
for i in range(n-1):
count += min(duration, timeSeries[i+1] - timeSeries[i])
return count

Reference

  1. https://leetcode.com/problems/teemo-attacking/
如果有收获,可以请我喝杯咖啡!