Python Solution 72 ms 97.5%


  • 0
    J

    Add duration if timeStep <= duration, else add timeStep. Add a full duration at the end.

    class Solution(object):
        def findPoisonedDuration(self, timeSeries, duration):
            """
            :type timeSeries: List[int]
            :type duration: int
            :rtype: int
            """
            if timeSeries == []:
                return 0
            ans = 0
            previousAtk = timeSeries[0]
            for i in timeSeries:
                if i - previousAtk >= duration:
                    ans += duration
                else:
                    ans += i-previousAtk
                previousAtk = i
            ans += duration
            return ans
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.