Optimized java Solution - 8ms


  • 0
    V

    '''

    public int findPoisonedDuration(int[] timeSeries, int duration) {
        if(timeSeries.length > 0){
            int lastDuration = timeSeries[0] + duration;
            int sumDuration = duration * timeSeries.length;
            int overlapDuration = 0;
            
            for(int i = 1;i<timeSeries.length;i++){
    
                if(lastDuration > timeSeries[i]){
                    overlapDuration += lastDuration - timeSeries[i];
                }
                lastDuration = timeSeries[i] + duration;
            }
            return sumDuration - overlapDuration;
        }
        return 0;
    }
    

    '''


Log in to reply
 

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