Java O(n) solution


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

Log in to reply
 

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