当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢

Unity shader learning notes (3) URP rendering pipeline shaded PBR shader template (ASE optimized version)

Grbl software: basic knowledge of simple explanation

OLED12864 液晶屏

TI毫米波雷达学习(一)

Shenji Bailian 3.52-prim
![Redis key value database [primary]](/img/47/10461d12720a9dd801f80ed1d3ad23.jpg)
Redis key value database [primary]

如何使用MITMPROXy

Gcnet: non - local Networks meet Squeeze excitation Networks and Beyond

Keepalived installation, use and quick start

Software testing Q & A
随机推荐
vite如何兼容低版本浏览器
Some descriptions of Mipi protocol of LCD
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
RGB infinite cube (advanced version)
JS determines whether the mobile terminal or the PC terminal
ESP8266与STC8H8K单片机联动——天气时钟
mysql的约束总结
【LeetCode】Day92-盛最多水的容器
File contains vulnerability (I)
mysql事务和隔离级别
How to use mitmproxy
页面打印插件print.js
Matplotlib double Y axis + adjust legend position
Software testing - concept
Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
js判断移动端还是pc端
数据回放伴侣Rviz+plotjuggler
uni-app开发中遇到的问题(持续更新)
MySQL transaction and isolation level