File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 396
396
492|[ Construct the Rectangle] ( ./0492-construct-the-rectangle.js ) |Easy|
397
397
493|[ Reverse Pairs] ( ./0493-reverse-pairs.js ) |Hard|
398
398
494|[ Target Sum] ( ./0494-target-sum.js ) |Medium|
399
+ 495|[ Teemo Attacking] ( ./0495-teemo-attacking.js ) |Easy|
399
400
496|[ Next Greater Element I] ( ./0496-next-greater-element-i.js ) |Easy|
400
401
500|[ Keyboard Row] ( ./0500-keyboard-row.js ) |Easy|
401
402
501|[ Find Mode in Binary Search Tree] ( ./0501-find-mode-in-binary-search-tree.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 495. Teemo Attacking
3
+ * https://leetcode.com/problems/teemo-attacking/
4
+ * Difficulty: Easy
5
+ *
6
+ * Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets
7
+ * poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is
8
+ * poisoned during the inclusive time interval [t, t + duration - 1]. If Teemo attacks again before
9
+ * the poison effect ends, the timer for it is reset, and the poison effect will end duration
10
+ * seconds after the new attack.
11
+ *
12
+ * You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo
13
+ * attacks Ashe at second timeSeries[i], and an integer duration.
14
+ *
15
+ * Return the total number of seconds that Ashe is poisoned.
16
+ */
17
+
18
+ /**
19
+ * @param {number[] } timeSeries
20
+ * @param {number } duration
21
+ * @return {number }
22
+ */
23
+ var findPoisonedDuration = function ( timeSeries , duration ) {
24
+ return timeSeries . reduce ( ( sum , n , i ) => {
25
+ return sum + Math . min ( duration , ( timeSeries [ i + 1 ] ?? n + duration ) - n ) ;
26
+ } , 0 ) ;
27
+ } ;
You can’t perform that action at this time.
0 commit comments