495.提莫攻击
链接:495.提莫攻击
难度:Easy
标签:数组、模拟
简介:返回艾希处于中毒状态的 总 秒数。
题解 1 - typescript
- 编辑时间:2021-11-10
- 执行用时:76ms
- 内存消耗:42.2MB
- 编程语言:typescript
- 解法介绍:遍历。
function findPoisonedDuration(timeSeries: number[], duration: number): number {
let ans = 0;
for (let i = 0, n = timeSeries.length; i < n - 1; i++) {
const time = timeSeries[i];
const next_time = timeSeries[i + 1];
if (time + duration - 1 >= next_time) ans += next_time - time;
else ans += duration;
}
ans += duration;
return ans;
}