Java esay understanding straight forward solution


  • 0
    X
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        if(timeSeries == null|| timeSeries.length == 0||duration == 0){
            return 0;
        }
        int total = 0;
        int end = timeSeries[0]+duration;
        for(int t:timeSeries){
            if(t>=end){
                total+=duration;
            }else{
                total+=t-(end-duration);
            }
            end = t+duration;
        }
        total+=duration;
        return total;
    }

Log in to reply
 

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