Very Short C++ O(N) Greedy Solutiuon


  • 1
    H

    class Solution {
    public:
    int findPosisonedDuration(vector<int>& timeSeries, int duration)
    {
    int poisonEnd = 0;
    int total(0);

        for(auto it : timeSeries)
        {
            poisonEnd = max(it, poisonEnd);
            total += (it + duration - poisonEnd);
            poisonEnd = it +  duration;
        }
        return total;
    }
    

    };'''


Log in to reply
 

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