链接
https://leetcode.cn/problems/teemo-attacking/description/
思路
这题思路其实很简单,需要2个变量,1个记住总数,1个记住之前遍历过的序列能够访问到的最大值。
如果遍历到某个数时,这个最大值比他大,就证明之前序列中的某个加和被浪费掉了,所以应该从total中减去差值。
代码
class Solution: def findPoisonedDuration(self, timeSeries, duration: int) -> int: total = 0 remains = 0 for time in timeSeries: total += duration if remains == 0: remains = time + duration else: if remains > time: total -= remains - time remains = time + duration return total
标签:攻击,remains,int,time,duration,495,提莫,total From: https://www.cnblogs.com/bjfu-vth/p/17712855.html