1. 程式人生 > >leetcode 495. Teemo Attacking

leetcode 495. Teemo Attacking

/**
 * 495. Teemo Attacking
 * @param timeseries
 * @param duration
 * @return
 * 2017年3月12日下午9:16:40
 */
public int findPoisonedDuration(int[] timeSeries, int duration) {
	if (timeSeries.length == 0)
		return 0;
	int res = 0;
	for (int i = 1; i<timeSeries.length; i++) {
		int span = timeSeries[i] - timeSeries[i-1]; 
		if (span > duration)
			res += duration;
		else 
			res += span; 
	}
	
	return res + duration;
}