my c++ solution, easy to understand.


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

Log in to reply
 

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