Leetcode 495 Solution

This article provides solution to leetcode question 495 (teemo-attacking)

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

Solution

class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int64_t end = 0;
        int64_t total = 0;

        for (int i = 0; i < timeSeries.size(); i++)
        {
            total += (int64_t)timeSeries[i] + duration - max(end, (int64_t)timeSeries[i]);
            end = (int64_t)timeSeries[i] + duration;
        }

        return total;
    }
};