Simple AC cpp solution


  • 0
    M
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
      int n = timeSeries.size();
      if (n < 1) {
        return 0;
      }
      
      int sum = duration;
      for (int i = n - 2; i >= 0; i--) {
        sum += (timeSeries[i + 1] - timeSeries[i] >= duration) ?
                duration : (timeSeries[i + 1] - timeSeries[i]);
      }
      
      return sum;
    }
    
    
    

Log in to reply
 

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