力扣-495. 提莫攻击

int findPoisonedDuration(int* timeSeries, int timeSeriesSize, int duration)
{
    int totalTimes = 0;/*中毒的总秒数*/
    int processTimes = 0;/*过程中,中毒的时间段秒数*/
    int i = 0;
    for(i = 0; i < timeSeriesSize - 1; i++)
    {
        if(timeSeries[i + 1] - timeSeries[i] >= duration)
        {
            totalTimes += duration;
        }
        else
        {
            processTimes += timeSeries[i + 1] - timeSeries[i];
        }
    }
    /*加一个duration是因为要把最后一次中毒的时间加上*/
    totalTimes = processTimes + totalTimes + duration;

    return totalTimes;
}

你可能感兴趣的:(LeetCode,leetcode,C语言)