C++ 9 lines simple, easy to understand solution


  • 0
    M
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
            if(timeSeries.size()==0) return 0;
            int res=0, end=timeSeries[0];
            for(int i=0;i<timeSeries.size();i++) {
                if(timeSeries[i]>end) res+=duration;
                else if(i>0) res+=timeSeries[i]-timeSeries[i-1];
                end=timeSeries[i]+duration-1;
            }
            res+=duration;
            return res;
        }

Log in to reply
 

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