easy&simple java solution


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

    }


Log in to reply
 

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