Java O(n) Easy to understand


  • 0
    K
    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            if(timeSeries.length == 0) return 0;
            int total = 0;
            for(int i = 0; i < timeSeries.length - 1; ++i)
            {
                if(timeSeries[i + 1] > duration + timeSeries[i] - 1)
                {
                    total += duration;
                }
                else
                {
                    total += (timeSeries[i+1]-timeSeries[i]);
                }
            }
            total += duration;
            return total;
        }
    }
    

Log in to reply
 

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