当前位置:网站首页>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主从复制原理?
- 记录——kubeadm集群node节点加入
- bypassuac提权
- 创新技术领航者!华为云GaussDB获颁2022年云原生数据库领域权威奖项
- TensorRT Paser加载onnx 推理使用
- Lamp architecture that your girlfriend can read
- [go] calling Alipay to scan code for payment in a sandbox environment
- Apache foundation officially announced Apache inlong as a top-level project
- How long does it take to open a stock account by mobile phone? Is online account opening safe?
- ASEMI快恢复二极管RS1M、US1M和US1G能相互代换吗
猜你喜欢

《MPLS和VP体系结构》

Redis cluster operation method

The company recruited a tester with five years' experience and saw the real test ceiling

Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)

读书郎通过上市聆讯:平板业务毛利率走低,2021年利润同比下滑11%

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

网络远程访问树莓派(VNC Viewer)

Troubleshooting of datanode entering stale status

接口的所有权之争

官方零基础入门 Jetpack Compose 的中文课程来啦
随机推荐
时间戳90K是什么意思?
Query the size of each table in the database
R language uses colorblinr package to simulate color blind vision, and uses edit to visualize the image of ggplot2_ The colors function is used to edit and convert color blindness into visual results
Online communication - the combination of machine learning and knowledge reasoning in trusted machine learning (Qing Yuan talk, issue 20, Li Bo)
数据库 实验二 查询
Counter attack by flour dregs: MySQL 66 question! Suggested collection
Intel arc A380 graphics card message summary: the entry-level price products of running point and bright driving need to be optimized
谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
ERP管理系统的重要性
How to configure MySQL log management
Date转换为LocalDateTime
供求两端的对接将不再是依靠互联网时代的平台和中心来实现的
TQ of R language using tidyquant package_ The transmute function calculates the daily, monthly and weekly returns of a stock. Ggplot2 uses the bar plot to visualize the monthly return data of the stoc
Case analysis of camera power supply disturbed, seriously affecting image quality
你女朋友也能读懂的LAMP架构
查数据库中每张表的大小
The Google play academy team PK competition is in full swing!
Here comes the official zero foundation introduction jetpack compose Chinese course!
使用Jmeter进行性能测试及性能监控平台搭建
相机电源受干扰案例分析,严重影响画质