Short and Easy to understand java O(n) solution


  • 0
    B

    public int findPoisonedDuration(int[] nums, int duration) {

        if(nums == null || nums.length == 0 || duration <= 0){
            return 0;
        }    
        
        int res = 0;
        int max = 0;
        
        for(int num: nums){
            if(max <= num){
                res += duration;
            }else{
                res += num + duration - max;
            }
            max = num + duration;
        }
        
        return res;
    }

Log in to reply
 

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