当前位置:网站首页>495. Timo attack
495. Timo attack
2022-07-02 06:00:00 【occasionally.】
1. Title Description
stay 《 Hero alliance 》 In the world of , One called “ Timo ” The hero of . His attack can make enemy hero ash ( Editor's note : Cold shooter ) Into a toxic state .
When Timo attacked ash , Ash's poisoning just continued duration second .
Formally speaking , Timo is here t Launching an attack means that ash is in a time interval [t, t + duration - 1]( contain t and t + duration - 1) In a state of poisoning . If Timo is at the end of the poisoning effect front Attack again , The poisoning status timer will Reset , After a new attack , The toxic effect will be in duration Seconds later .
To give you one The decreasing Array of integers for timeSeries , among timeSeries[i] It means Timo is timeSeries[i] Attack ash in seconds , And an integer representing the duration of poisoning duration .
Returns the total number of seconds that ash is poisoned .
Input :timeSeries = [1,4], duration = 2
Output :4
explain : The impact of Timo's attack on ash is as follows :
- The first 1 second , Timo attacked ash and poisoned him immediately . The toxic state will be maintained 2 second , That is to say 1 Second and the 2 second .
- The first 4 second , Timo attacked ash again , Aishi's poisoning continued 2 second , That is to say 4 Second and the 5 second .
Ash's on the third floor 1、2、4、5 Seconds is poisoned , So the total poisoning seconds are 4
2. Their thinking
① The total poisoning seconds are at least duration second , because timeSeries At the last moment, ash can always be poisoned duration second
② Traverse timeSeries, Judge timeSeries Whether the interval between adjacent times in is greater than duration, If greater than or equal to , Poisoning seconds increase duration, If less than , Increase the interval .
- python3
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
res = duration
if duration == 0:
return 0
for i in range(1,len(timeSeries)):
if timeSeries[i] - timeSeries[i-1] >= duration:
res += duration
else:
res += timeSeries[i] - timeSeries[i-1]
return res
- c++
class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
int res = duration;
if (duration == 0)
return 0;
for (int i=1; i < timeSeries.size(); i++){
if (timeSeries[i]-timeSeries[i-1] >= duration)
res += duration;
else
res += timeSeries[i] - timeSeries[i-1];
}
return res;
}
};
边栏推荐
- Lantern Festival gift - plant vs zombie game (realized by Matlab)
- Verifying downloaded files using sha256 files
- Go 学习笔记整合
- mock-用mockjs模拟后台返回数据
- Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock
- 外部中断无法进入,删代码再还原就好......记录这个想不到的bug
- Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders
- JWT tool class
- Vite打包后的dist不能直接在浏览器打开吗
- Stick to the big screen UI, finereport development diary
猜你喜欢
随机推荐
cookie插件和localForage离线储存插件
神机百炼3.54-染色法判定二分图
php读文件(读取json文件,转换为数组)
Page printing plug-in print js
Stick to the big screen UI, finereport development diary
1035 Password
Stc8h8k Series Assembly and c51 Real combat - NIXIE TUBE displays ADC, Key Series port reply Key number and ADC value
Go language web development is very simple: use templates to separate views from logic
Stc8h8k series assembly and C51 actual combat - keys allow key counting (using falling edge interrupt control)
TI毫米波雷达学习(一)
Software testing - concept
Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock
PHP development and testing WebService (soap) -win
ROS2----LifecycleNode生命周期节点总结
【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
PHP 开发与测试 Webservice(SOAP)-Win
使用sha256文件验证下载的文件
复杂 json数据 js前台解析 详细步骤《案例:一》
格式校验js
Servlet web XML configuration details (3.0)