In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, you need to output the total time that Ashe is in poisoned condition.
You may assume that Teemo attacks at the very beginning of a specific time point, and makes Ashe be in poisoned condition immediately.
class Solution {
public:int findPoisonedDuration(vector<int>& timeSeries, int duration) {
int total = 0;
if(timeSeries.size() == 0) {
return total;
}
else {
for(int i = 0; i < timeSeries.size(); i++) {
if(i != timeSeries.size()-1) {
if(timeSeries[i+1] - timeSeries[i] >= duration) {
total += duration;
}
else {
total += timeSeries[i+1] - timeSeries[i];
}
}
else total += duration;
}
}
return total;
}
};