Easy Understand Java Solution


  • 0
    W
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            int sumPointedTime = timeSeries.length == 0 ? 0 : duration;
            for (int i = 1; i < timeSeries.length; i++) {
                if (timeSeries[i] - timeSeries[i - 1] >= duration) {
                    sumPointedTime += duration;
                } else {
                    sumPointedTime += timeSeries[i] - timeSeries[i - 1];
                }
            }
            return sumPointedTime;
        }
    
    

Log in to reply
 

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