Teemo Attacking
思路一: 对两个前后攻击序列,完全分类只可能出现两种情况,只要把重叠的时间都减去,就是所求时间。此分类对三个以上的重叠时间依旧成立
- 没有重叠,攻击时间累加
- 有重叠,攻击时间需要去除重叠部分
public int findPoisonedDuration(int[] timeSeries, int duration) {
int result = timeSeries.length * duration;
for (int i = 0; i < timeSeries.length - 1; i++) {
int left = timeSeries[i];
int right = timeSeries[i+1];
int gap = left + duration - right;
if (gap > 0) {
result -= gap;
}
}
return result;
}
标签:easy,int,gap,result,timeSeries,duration,495,leetcode,重叠
From: https://www.cnblogs.com/iyiluo/p/16804882.html