Teemo Attacking

Problem Id: 495 Difficulty: Medium


Intuition

Solution


class Solution:
    def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
        if not timeSeries:
            return 0
        start = timeSeries[0]
        ans = 0
        for attack in timeSeries:
            if start + duration >= attack:
                ans += attack - start
            else:
                ans += duration
            start = attack
        ans += duration
        return ans