leetcode495

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

leetcode打卡——区间维护问题——495. 提莫攻击

leetcode495

[leetcode-495-Teemo Attacking]

Leetcode 495: Teemo Attacking

LeetCode 495. Teemo Attacking(medium)

LeetCode --- 495. Teemo Attacking 解题报告