https://leetcode.com/problems/teemo-attacking/description/
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
if(timeSeries.size() == 0) return 0;
int res = 0, next = timeSeries[0];
for(int n: timeSeries) {
if(n+duration-1 >= next) {
if(n <= next) res += n + duration - next;
else res += duration;
next = n + duration;
}
}
return res;
}
No comments:
Post a Comment