Easy Java Solution


  • 0
    G

    sum is the total poison time. time is the ith poison can last to.

    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int sum = 0;
        int time = 0;
        
        for(int i:timeSeries){
            if(i>=time) sum+=duration;
            else sum += i+duration-time;
            time = i+duration;
        }
        return sum;
    }

Log in to reply
 

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