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

posted on 2017-05-03 10:30  Sempron2800+  阅读(123)  评论(0编辑  收藏  举报