当前位置:网站首页>Li Kou daily question - day 25 -495 Timo attack
Li Kou daily question - day 25 -495 Timo attack
2022-06-23 17:21:00 【Chongyou research Sen】
2022.6.23 Did you brush the questions today ?
subject :
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 .
Return to ash's poisoned total Number of seconds .
analysis :
This question means , Given an increasing array and a fixed value , Start with the first element of the array , Let it come from x Add in sequence as x+1,x+2,,x+ Set value , Then iterate over the second element of the array y, Also repeat y+1,y+2,,y+ Set value , And then add these numbers , How many in all , The number of repetitions is counted only once . for example
【1,3】,n=2 1+1,1+2,3+1,3+2, So that is 4
【1,3】,n=3 1+1,1+2,1+3,3+1,3+2,3+3, So that is 6
So we can save these numbers every time map in , Then count map Just a few of them ( But the operation timed out !!!)
analysis :
1. Hashtable
class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
unordered_map<int, int>map;
int res = 0;
for (auto num : timeSeries)
{
int val = num;
for (; num < val + duration; num++)
{
map[num]++;
}
}
return map.size();
}
};2. Common solution
Thought is : By comparing the difference between the two numbers before and after a given array and comparing the fixed value , Find the first number “ Valid values ”, And the last number “ Valid values ” Then it is the constant value , Finally, put these “ The valid values add up to the answer
class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
int ans = duration;
int res = 0;
for (int i = 1; i < timeSeries.size(); i++)
{
res = min(timeSeries[i] - timeSeries[i - 1], duration);
ans += res;
}
return ans;
}
};边栏推荐
- 谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
- DataNode进入Stale状态问题排查
- 开户券商怎么选择?现在网上开户安全么?
- 相机电源受干扰案例分析,严重影响画质
- Hapoxy-集群服务搭建
- 【网络通信 -- WebRTC】WebRTC 源码分析 -- PacingController 相关知识点补充
- How to use SQL window functions
- How can the points mall make profits
- ABAP随笔-物料主数据界面增强
- How about stock online account opening and account opening process? Is online account opening safe?
猜你喜欢

图扑软件以轻量化建模构建智慧城市

ctfshow php的特性

Apache基金会正式宣布Apache InLong成为顶级项目

Importance and purpose of test

I successfully joined the company with 27K ByteDance. This interview notes on software testing has benefited me for life

Safe and comfortable, a new generation of Qijun carefully interprets the love of the old father
![[go] calling Alipay to scan code for payment in a sandbox environment](/img/d4/c6d72a697bc08f69f11121a15109b3.png)
[go] calling Alipay to scan code for payment in a sandbox environment

How important is 5g dual card dual access?

Apache foundation officially announced Apache inlong as a top-level project

Comparison of asemi Schottky diode and ultrafast recovery diode in switching power supply
随机推荐
Comparison of asemi Schottky diode and ultrafast recovery diode in switching power supply
[today in history] June 23: Turing's birthday; The birth of the founder of the Internet; Reddit goes online
面渣逆袭:MySQL六十六问!建议收藏
Date转换为LocalDateTime
Why do we say that the data service API is the standard configuration of the data midrange?
ADC digital DGND, analog agnd mystery!
Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
Digital twin excavator of Tupu software realizes remote control
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)
How to select an oscilloscope? These 10 points must be considered!
美团三面:聊聊你理解的Redis主从复制原理?
ASEMI肖特基二极管和超快恢复二极管在开关电源中的对比
移动云共筑信创云能力底座,助力中国信创产业发展
How can the points mall make profits
手机开户股票开户需要多久?在线开户安全么?
官方零基础入门 Jetpack Compose 的中文课程来啦!
如何选择示波器?这10点一定要考虑!
Date to localdatetime
Innovative technology leader! Huawei cloud gaussdb won the 2022 authoritative award in the field of cloud native database
IFLYTEK neuroimaging disease prediction program!