easy to understand O(n) solution


  • 0
    B
        public int findPoisonedDuration(int[] a, int duration) {
            if(a.length == 0){
                return 0;
            }
            
            int t = 0;
            int diff = 0;
            for(int i =1; i<a.length; i++){
                diff = a[i] - a[i-1];
                if(diff > duration){
                    t+= duration;
                }
                else{
                    t+=diff;
                }
            }
            
            t+= duration;
            return t;
        }
    
    

Log in to reply
 

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