Easy to Understand, coding exactly same as thought! JAVA Solution!


  • 0
    T
    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            
            if(timeSeries.length == 0)  return 0;
            
            int total = 0, end = timeSeries[0];
            
            for(int t: timeSeries) {
                
                if(t > end){
                    total += duration;
                    end   = t + duration;
                }
                else if(t == end){
                    total += duration;
                    end   += duration;
                }
                else{
                    total += Math.max(0, t + duration - end);
                    end   += Math.max(0, t + duration - end);
                }
            }
            
            return total;
        }
    }
    

Log in to reply
 

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