---
# System prepended metadata

title: \#495 Teemo Attacking
tags: [leetcode, leetcode-easy]

---

# \#495 Teemo Attacking
## *遞增數字陣列timeSeries表示中毒的時間點(秒), duration表示中毒持續秒數, 在中毒期間再次受毒則持續秒數重置, 回傳實際的中毒持續秒數*
## Log
 - build 20210922 by syhuang

## 初見
 - 跑迴圈計算(下次中毒時間點-此次中毒時間點), 間隔\<duration則只增加差秒, 否則增加完整duration秒數
 - leetcode submit runtime 61%, memory 59%
```javascript=
var findPoisonedDuration = function(timeSeries, duration) {
    if(timeSeries.length == 1) return duration;
    let result = 0;
    for(let i=timeSeries.length-1; i>0; i--){
        let diff = timeSeries[i] - timeSeries[i-1];
        result += (diff>=duration)?duration:diff;
    }
    result+=duration;//last attack
    return result;
};
```
## 備註
- 初見即畢業
## 參考
###### tags: `leetcode`, `leetcode-easy`