class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
int ret = duration;
for (int i = 1; i < timeSeries.size(); ++i)
ret += min(duration, timeSeries[i] - timeSeries[i-1]);
return ret;
}
};