495. Teemo Attacking Easy
1/**
2 * [495] Teemo Attacking
3 *
4 * Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.
5 * You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration.
6 * Return the total number of seconds that Ashe is poisoned.
7 *
8 * Example 1:
9 *
10 * Input: timeSeries = [1,4], duration = 2
11 * Output: 4
12 * Explanation: Teemo's attacks on Ashe go as follows:
13 * - At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
14 * - At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.
15 * Ashe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.
16 *
17 * Example 2:
18 *
19 * Input: timeSeries = [1,2], duration = 2
20 * Output: 3
21 * Explanation: Teemo's attacks on Ashe go as follows:
22 * - At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
23 * - At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.
24 * Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.
25 *
26 * Constraints:
27 *
28 * 1 <= timeSeries.length <= 10^4
29 * 0 <= timeSeries[i], duration <= 10^7
30 * timeSeries is sorted in non-decreasing order.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/teemo-attacking/
36// discuss: https://leetcode.com/problems/teemo-attacking/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn find_poisoned_duration(time_series: Vec<i32>, duration: i32) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_495() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.