Description:

https://leetcode.com/problems/teemo-attacking/description/

Code:

 

Time & Space:
O(n) & O(1)

1 comments

A shorter version:

class Solution {
public:
int findPoisonedDuration(vector& timeSeries, int duration) {
int ans = 0, awake = 0;
for (auto x : timeSeries) {
ans += (x > awake) ? duration : x + duration – awake;
awake = x + duration;
}
return ans;
}
};

Leave a Reply

*