Teemo Attacking — LeetCode 495 Python Solution
EasyArraySimulation
- Problem
- #495
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds.
Example
- Input
- timeSeries = [1,4], duration = 2
- Output
- 4
- Explanation
- Teemo's attacks on Ashe go as follows:
Python solution
Python
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
ans = duration
for a, b in pairwise(timeSeries):
ans += min(duration, b - a)
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
LeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1389Create Target Array in the Given OrderEasyLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMediumLeetCode 1535Find the Winner of an Array GameMediumLeetCode 1560Most Visited Sector in a Circular TrackEasy
Frequently asked questions
- How hard is LeetCode 495. Teemo Attacking?
- LeetCode 495. Teemo Attacking is rated Easy on LeetCode.
- What topics does LeetCode 495. Teemo Attacking cover?
- LeetCode 495. Teemo Attacking is tagged Array and Simulation on LeetCode.