File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1
1
# LeetCode Algorithms
2
2
3
- ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-162 /2081-1f425f.svg )
4
- ![ problems-solved-java] ( https://img.shields.io/badge/Java-162 /2081-1abc9c.svg )
5
- ![ problems-solved-python] ( https://img.shields.io/badge/Python-162 /2081-1abc9c.svg )
3
+ ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-163 /2081-1f425f.svg )
4
+ ![ problems-solved-java] ( https://img.shields.io/badge/Java-163 /2081-1abc9c.svg )
5
+ ![ problems-solved-python] ( https://img.shields.io/badge/Python-163 /2081-1abc9c.svg )
6
6
[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg )] ( CONTRIBUTING.md )
7
7
[ ![ cp] ( https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg )] ( https://github.com/anishLearnsToCode/competitive-programming )
8
8
133
133
| 482 | [ License Key Formatting] ( https://leetcode.com/problems/license-key-formatting ) | [ ![ Java] ( assets/java.png )] ( src/LicenseKeyFormatting.java ) [ ![ Python] ( assets/python.png )] ( python/license_key_formatting.py ) |
134
134
| 485 | [ Max Consecutive Ones] ( https://leetcode.com/problems/max-consecutive-ones ) | [ ![ Java] ( assets/java.png )] ( src/MaxConsecutiveOnes.java ) [ ![ Python] ( assets/python.png )] ( python/max_consecutive_ones.py ) |
135
135
| 492 | [ Construct the Rectangle] ( https://leetcode.com/problems/construct-the-rectangle ) | [ ![ Java] ( assets/java.png )] ( src/ConstructTheRectangle.java ) [ ![ Python] ( assets/python.png )] ( python/construct_the_rectangle.py ) |
136
+ | 495 | [ Teemo Attacking] ( https://leetcode.com/problems/teemo-attacking/ ) | [ ![ Java] ( assets/java.png )] ( src/TeemoAttacking.java ) [ ![ Python] ( assets/python.png )] ( python/teemo_attacking.py ) |
136
137
| 496 | [ Next Greater Element I] ( https://leetcode.com/problems/next-greater-element-i ) | [ ![ Java] ( assets/java.png )] ( src/NextGreaterElementI.java ) [ ![ Python] ( assets/python.png )] ( python/next_greater_element_i.py ) |
137
138
| 500 | [ Keyboard Row] ( https://leetcode.com/problems/keyboard-row ) | [ ![ Java] ( assets/java.png )] ( src/KeyBoardRow.java ) [ ![ Python] ( assets/python.png )] ( python/keyboard_row.py ) |
138
139
| 501 | [ Find Mode in Binary Search Tree] ( https://leetcode.com/problems/find-mode-in-binary-search-tree ) | [ ![ Java] ( assets/java.png )] ( src/FindModeInBinarySearchTree.java ) [ ![ Python] ( assets/python.png )] ( python/find_mode_in_binary_search_tree.py ) |
Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
3
+
4
+ class Solution :
5
+ def findPoisonedDuration (self , timeSeries : List [int ], duration : int ) -> int :
6
+ poisonDuration = 0
7
+ index , current = 0 , timeSeries [0 ] - 1
8
+ while index < len (timeSeries ):
9
+ poisonDuration += duration - (current - timeSeries [index ] + 1 )
10
+ current = max (
11
+ timeSeries [index ] + duration - 1 ,
12
+ timeSeries [index + 1 ] - 1 if index < len (timeSeries ) - 1 else 0
13
+ )
14
+ index += 1
15
+ return poisonDuration
Original file line number Diff line number Diff line change
1
+ public class TeemoAttacking {
2
+ public static void main (String [] args ) {
3
+ System .out .println (findPoisonedDuration (new int [] {1 , 2 }, 2 ));
4
+ }
5
+
6
+ public static int findPoisonedDuration (int [] timeSeries , int duration ) {
7
+ int poisonDuration = 0 ;
8
+ for (int i = 0 , current = timeSeries [0 ] - 1 ; i < timeSeries .length ; i ++) {
9
+ poisonDuration += duration - Math .max (0 , Math .max (current , timeSeries [i ] - 1 ) - timeSeries [i ] + 1 );
10
+ current = timeSeries [i ] + duration - 1 ;
11
+ }
12
+ return poisonDuration ;
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments