首页 > 代码库 > leetcode495

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

leetcode495