美文网首页Leetcode
Leetcode 495. Teemo Attacking

Leetcode 495. Teemo Attacking

作者: SnailTyan | 来源:发表于2021-07-21 15:11 被阅读0次

    文章作者: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

        本文链接:https://www.haomeiwen.com/subject/zcsiultx.html