public class Solution {

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

if(timeSeries.length==0) return 0;

int total =0;

int begin = timeSeries[0];

for(int i =1;i<timeSeries.length;i++){

int gap = timeSeries[i]-begin;

total += gap < duration ? gap : duration;

begin = timeSeries[i];

}

return total + duration;

}

}