Package g0401_0500.s0495_teemo_attacking
Class Solution
java.lang.Object
g0401_0500.s0495_teemo_attacking.Solution
495 - Teemo Attacking.<p>Easy</p>
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. If Teemo attacks again <strong>before</strong> the poison effect ends, the timer for it is <strong>reset</strong> , and the poison effect will end <code>duration</code> seconds after the new attack.</p>
<p>You are given a <strong>non-decreasing</strong> integer array <code>timeSeries</code>, where <code>timeSeries[i]</code> denotes that Teemo attacks Ashe at second <code>timeSeries[i]</code>, and an integer <code>duration</code>.</p>
<p>Return <em>the <strong>total</strong> number of seconds that Ashe is poisoned</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> timeSeries = [1,4], duration = 2</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> Teemo’s attacks on Ashe go as follows: - At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2. - At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5. Ashe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> timeSeries = [1,2], duration = 2</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>Teemo’s attacks on Ashe go as follows:</p>
<ul>
<li>
<p>At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.</p>
</li>
<li>
<p>At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3. Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.</p>
</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= timeSeries.length <= 10<sup>4</sup></code></li>
<li><code>0 <= timeSeries[i], duration <= 10<sup>7</sup></code></li>
<li><code>timeSeries</code> is sorted in <strong>non-decreasing</strong> order.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findPoisonedDuration
public int findPoisonedDuration(int[] timeSeries, int duration)
-