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 ...
随机推荐
- Web 监听器
什么事web 监听器? Servlet规范中定义的一种特殊类 用于监听ServletContext.HttpSession和ServletRequest等象的创建与销毁的事件 用监听域对象的属性发生修 ...
- Apache Flink 1.5.1 Released
Apache Flink: Apache Flink 1.5.1 Released http://flink.apache.org/news/2018/07/12/release-1.5.1.html ...
- linux下如何用php读取word
在实际的工作中遇到到要导入word格式的文件,经过努力,终于成功了. 在linux上用PHP读取WORD文档,其实是使用了 antiword程序把word文档转化为txt文档. 再使用php执行系统命 ...
- 设置sublime text2/3中预览浏览器快捷键的方法
我们为什么要设置默认的预览浏览器呢?因为搞前端的都知道,你在预览的时候不可能只预览一个浏览器,可能需要多个,当然今天我们举例中会说道谷歌浏览器Chrome,IE浏览器Internet Explorer ...
- poj 1258 Agri-Net 解题报告
题目链接:http://poj.org/problem?id=1258 题目意思:给出 n 个 farm,每个farm 之间通过一定数量的fiber 相连,问使得所有farm 直接或间接连通的 最少 ...
- html5--6-57 阶段练习6-折叠导航栏
html5--6-57 阶段练习6-折叠导航栏 实例 @charset="UTF-8"; *{ ; ; } h3+div{ ; overflow: hidden; transiti ...
- python中的异常处理try/except/finally/raise
异常发生在程序执行的过程中,如果python无法正常处理程序就会发生异常,导致整个程序终止执行,python中使用try/except语句可以捕获异常. try/except 异常的种类有很多,在不确 ...
- SPOJ:Strange Waca(不错的搜索&贪心&剪枝)
Waca loves maths,.. a lot. He always think that 1 is an unique number. After playing in hours, Waca ...
- iOS NSInteger/NSUInteger与int/unsigned int、long/unsigned long之间的区别!
在iOS开发中经常使用NSInteger和NSUInteger,而在其他的类似于C++的语言中,我们经常使用的是int.unsigned int.我们知道iOS也可以使用g++编译器,那么它们之间是否 ...
- RDA PQ工具使用 (Adi Analysis)
PQ工具“ColorAdjustTool.exe”,请注意芯片的选择: RDA512C选择533 RDA8501选择331 RDA8503选择131 工模菜单 COLOR LUT: R/G/B/Y/ ...