Easy understand java


  • 0
    N
    public int findPoisonedDuration(int[] timeSeries, int duration) {
            if(timeSeries == null || timeSeries.length == 0 || duration <= 0){
                return 0;
            }
            
            int res = 0;
            int index = 0;
            int curEnd = timeSeries[0] + duration;
            
            for(int i = 1; i<timeSeries.length; i++){
                if(timeSeries[i] > curEnd){
                    res += curEnd - timeSeries[index];
                    index = i;
                }
                curEnd = timeSeries[i] + duration;
            }
            res += curEnd - timeSeries[index];
            
            return res;
        }

Log in to reply
 

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