Leetcode 495. Teemo Attacking

Posted SnailTyan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 495. Teemo Attacking相关的知识,希望对你有一定的参考价值。

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

1. Description

Teemo Attacking

2. Solution

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

  • Version 1
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
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/

以上是关于Leetcode 495. Teemo Attacking的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 495. Teemo Attacking(medium)

LeetCode --- 495. Teemo Attacking 解题报告

Leetcode 495. Teemo Attacking

495. Teemo Attacking

495. Teemo Attacking

495. Teemo Attacking