Leetcode 495. Teemo Attacking

2021-07-08 16:27:09 浏览数 (1)

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

1. Description

2. Solution

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

  • Version 1
代码语言:javascript复制
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
代码语言:javascript复制
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/

0 人点赞