Skip to content

Commit 797ac30

Browse files
solves teemo attacking
1 parent 16ef2d0 commit 797ac30

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# LeetCode Algorithms
22

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)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77
[![cp](https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg)](https://github.com/anishLearnsToCode/competitive-programming)
88

@@ -133,6 +133,7 @@
133133
| 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) |
134134
| 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) |
135135
| 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) |
136137
| 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) |
137138
| 500 | [Keyboard Row](https://leetcode.com/problems/keyboard-row) | [![Java](assets/java.png)](src/KeyBoardRow.java) [![Python](assets/python.png)](python/keyboard_row.py) |
138139
| 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) |

python/teemo_attacking.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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

src/TeemoAttacking.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

0 commit comments

Comments
 (0)