C++ simple 5 lines


  • 1
    B
    class Solution {
    public:
        int findPoisonedDuration(vector<int>& timeSeries, int duration) {
            int ans = 0, last = -1;
            for(auto e : timeSeries)
            {
                if(last > e) ans -= last - e;
                ans += duration;
                last = e + duration;
            }
            return ans;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.