clueless coding // TODO: be smarter

LeetCode Teemo Attacking: CPP Solution



TL;DR Code Solution


int findPoisonedDuration(vector<int>& timeSeries, int duration) {
    int result = timeSeries.size() * duration;
    for (int i = 1; i < timeSeries.size(); i++) {
        int overlap = timeSeries[i] - timeSeries[i - 1];
        if (overlap < duration) {
            result -= duration - overlap;
        }
    }
    return result;
}