5 lines C++ solution


  • 0
    F
       int findPoisonedDuration(vector<int>& timeSeries, int duration) {
            int res = duration;
            for(int i = 1; i < timeSeries.size(); i++) {
                res += min(duration, timeSeries[i] - timeSeries[i - 1]);
            }
            return timeSeries.size() == 0 ? 0 : res;
        }
    

Log in to reply
 

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