a python solution


  • 0
    J

    A linear time solution using python

    def findPoisonedDuration(self, timeSeries, duration):
            """
            :type timeSeries: List[int]
            :type duration: int
            :rtype: int
            """
            preTime, poisonTime = -1, -1
            answer = 0
            for newTime in timeSeries:
                if newTime > poisonTime:
                    answer += duration
                if newTime == poisonTime:
                    answer = answer + duration
                if newTime < poisonTime:
                    answer = answer + (newTime - preTime)
                poisonTime = newTime + duration
                preTime = newTime
            return answer
    

Log in to reply
 

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