4 lines O(n) Python

  • 3
    class Solution(object):
        def findPosisonedDuration(self, timeSeries, duration):
            :type timeSeries: List[int]
            :type duration: int
            :rtype: int
            ans = 0
            for i in range(len(timeSeries) - 1):
                ans += min(duration, timeSeries[i+1] - timeSeries[i])
            return ans + duration if timeSeries else 0

Log in to reply

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