495 Teemo Attacking 提莫攻击
在《英雄联盟》的世界中,有一个叫“提莫”的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态。现在,给出提莫对艾希的攻击时间序列和提莫攻击的中毒持续时间,你需要输出艾希的中毒状态总时长。
你可以认为提莫在给定的时间点进行攻击,并立即使艾希处于中毒状态。
示例1:
输入: [1,4], 2
输出: 4
原因: 在第1秒开始时,提莫开始对艾希进行攻击并使其立即中毒。中毒状态会维持2秒钟,直到第2秒钟结束。
在第4秒开始时,提莫再次攻击艾希,使得艾希获得另外2秒的中毒时间。
所以最终输出4秒。
示例2:
输入: [1,2], 2
输出: 3
原因: 在第1秒开始时,提莫开始对艾希进行攻击并使其立即中毒。中毒状态会维持2秒钟,直到第2秒钟结束。
但是在第2秒开始时,提莫再次攻击了已经处于中毒状态的艾希。
由于中毒状态不可叠加,提莫在第2秒开始时的这次攻击会在第3秒钟结束。
所以最终输出3。
注意:
1.你可以假定时间序列数组的总长度不超过10000。
2.你可以假定提莫攻击时间序列中的数字和提莫攻击的中毒持续时间都是非负整数,并且不超过10,000,000。
详见:https://leetcode.com/problems/teemo-attacking/description/
C++:
class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
if(timeSeries.empty())
{
return 0;
}
int res=0,n=timeSeries.size();
for(int i=1;i<n;++i)
{
int diff=timeSeries[i]-timeSeries[i-1];
res+=(diff<duration)?diff:duration;
}
return res+duration;
}
};
参考:https://www.cnblogs.com/grandyang/p/6399408.html
495 Teemo Attacking 提莫攻击的更多相关文章
- [LeetCode] 495. Teemo Attacking 提莫攻击
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...
- [LeetCode] Teemo Attacking 提莫攻击
In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...
- LeetCode 495. Teemo Attacking (提莫攻击)
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...
- 【LeetCode】495. Teemo Attacking 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 495. Teemo Attacking
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...
- [Swift]LeetCode495. 提莫攻击 | Teemo Attacking
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...
- Java实现 LeetCode 495 提莫攻击
495. 提莫攻击 在<英雄联盟>的世界中,有一个叫 "提莫" 的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态.现在,给出提莫对艾希的攻击时间序列和 ...
- [Leetcode]495.提莫攻击
题目: 在<英雄联盟>的世界中,有一个叫 "提莫" 的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态.现在,给出提莫对艾希的攻击时间序列和提莫攻击的中 ...
- leetcode解题报告(32):Teemo Attacking
描述 In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poison ...
随机推荐
- gdb调试使用autotools工程的项目
1 保留debug sympol和优化等级设置为-O0的最简单的方法 在执行configure脚本生成Makefile文件时,使用CXXFLAGS宏,因为标准的configure脚本给了这个宏. .. ...
- update外联表,用另一个表数据更新本表数据
update s set s.classbid = lc.itemidfrom dbo.Lv_servers as s INNER JOIN dbo.Lv_LineChannel as lc O ...
- 文件读写&&内容替换
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- adb client, adb server, adbd原理浅析(附带我的操作过程)【转】
本文转载自:http://blog.csdn.net/stpeace/article/details/24933813 adb是什么? adb就是Android调试桥,很形象啊. 先来看adb原理的逻 ...
- POJ1077 Eight —— 正向BFS
主页面:http://www.cnblogs.com/DOLFAMINGO/p/7538588.html 代码一:以数组充当队列,利用结构体中的pre追溯上一个状态在数组(队列)中的下标: #incl ...
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
01 Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- LoadRunner检查点使用小结
LR中检查点有两种:图片和文字. 常用检查点函数如下: 1)web_find()函数用于从 HTML 页中搜索指定的文本字符串: 2)web_reg_find()函数注册一个请求,以在下一个操作函数( ...
- 以太坊EVM1.0缺陷
256位的虚拟机 目前主流的CPU是32位或64位,在这些机器上进行256位运算需要将256位分段成多个64位指令执行,执行效率比32/64位低,在存储上方面,保存一个数需要256位的存储空间,绝大多 ...
- 原:maven+springMVC+mybatis+junit详细搭建过程
阅读目录 1. 工程目录结构整理清楚 2. 引入依赖包 3. 配置数据库连接属性 4. 配置spring配置文件 5. java代码编写(model,dao,service层代码) 6. m ...
- MyBatis学习 之 五、MyBatis配置文件
在定义sqlSessionFactory时需要指定MyBatis主配置文件: <bean id="sqlSessionFactory" class="org.myb ...