leetcode495

public class Solution {
    public int FindPoisonedDuration(int[] timeSeries, int duration) {
        if (timeSeries == null || timeSeries.Length == 0)
            {
                return 0;
            }
            else if (timeSeries.Length == 1)
            {
                return duration;
            }
            else
            {
                var sum = 0;
                for (int i = 0; i < timeSeries.Length - 1; i++)
                {
                    var cur = timeSeries[i];
                    var next = timeSeries[i + 1];

                    if (cur + duration <= next)
                    {
                        sum += duration;
                    }
                    else
                    {
                        sum += next - cur;
                    }
                }
                sum += duration;
                return sum;
            }
    }
}

https://leetcode.com/problems/teemo-attacking/#/description

原文地址:https://www.cnblogs.com/asenyang/p/6800586.html