In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition.
Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking,
you need to output the total time that Ashe is in poisoned condition.
You may assume that Teemo attacks at the very beginning of a specific time point,
and makes Ashe be in poisoned condition immediately.
Example 1:
Input: [1,4], 2
Output: 4
Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned immediately.
This poisoned status will last 2 seconds until the end of time point 2.
And at time point 4, Teemo attacks Ashe again, and causes Ashe to be in poisoned status for another 2 seconds.
So you finally need to output 4.
Example 2:
Input: [1,2], 2
Output: 3
Explanation: At time point 1, Teemo starts attacking Ashe and makes Ashe be poisoned.
This poisoned status will last 2 seconds until the end of time point 2.
However, at the beginning of time point 2, Teemo attacks Ashe again who is already in poisoned status.
Since the poisoned status won't add up together, though the second poisoning attack will still work at time point 2,
it will stop at the end of time point 3.So you finally need to output 3.

思路:

两种情况:

1,不存在覆盖,直接加上duration即可。

2,存在覆盖,则持续时间为相邻两个timeSeries之差。

int findPoisonedDuration(vector<int>& timeSeries, int duration)
{
int ret = ;
int n = timeSeries.size();
if (n == )return ;
if (n == )return duration; for (int i = ; i < n - ; i++)
{
if (timeSeries[i] + duration > timeSeries[i + ])//超过了
{
ret = ret + timeSeries[i + ] - timeSeries[i];
}
else
{
ret += duration;
}
}
ret += duration;
return ret;
}

[leetcode-495-Teemo Attacking]的更多相关文章

  1. LeetCode 495. Teemo Attacking (提莫攻击)

    In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...

  2. [LeetCode] 495. Teemo Attacking 提莫攻击

    In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...

  3. 【LeetCode】495. Teemo Attacking 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. 495. Teemo Attacking

    In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...

  5. 495 Teemo Attacking 提莫攻击

    在<英雄联盟>的世界中,有一个叫“提莫”的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态.现在,给出提莫对艾希的攻击时间序列和提莫攻击的中毒持续时间,你需要输出艾希的中毒 ...

  6. [LeetCode] Teemo Attacking 提莫攻击

    In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...

  7. leetcode解题报告(32):Teemo Attacking

    描述 In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poison ...

  8. [Swift]LeetCode495. 提莫攻击 | Teemo Attacking

    In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...

  9. Java实现 LeetCode 495 提莫攻击

    495. 提莫攻击 在<英雄联盟>的世界中,有一个叫 "提莫" 的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态.现在,给出提莫对艾希的攻击时间序列和 ...

  10. [Leetcode]495.提莫攻击

    题目: 在<英雄联盟>的世界中,有一个叫 "提莫" 的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态.现在,给出提莫对艾希的攻击时间序列和提莫攻击的中 ...

随机推荐

  1. 转:Java compiler level does not match the version of the installed Java project facet

    a.问题描述:eclipse加载新的项目后报一个错误,具体描述如下: Description Resource PathLocation Type Java compiler level does n ...

  2. MyEclipse修改项目名称后,部署到tomcat问题。

    1.问题描述: 修改项目名称后,部署到tomcat server,部署出来的文件夹名还是旧的名称. 2.解决方案: 光把项目重命名是不够的,还要修改一下Myeclipse里面的配置. a). 工程名- ...

  3. HiveHbase集成实践

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl/p/6857891.html 转载请注明出处 简单的说就是可以通过Hive SQL直接对hbase的表进行读写操 ...

  4. struts-config.xml的配置

    1.<struts-config>  元素 <struts-cofnig> 元素是 Struts 配置文件的根元素.<struts-config> 元素有 8 个子 ...

  5. 搜索技术---solr

    solr 企业站内搜索技术选型 在一些大型门户网站.电子商务网站等都需要站内搜索功能,使用传统的数据库查询方式实现搜索无法满足一些高级的搜索需求,比如:搜索速度要快.搜索结果按相关度排序.搜索内容格式 ...

  6. Day4-迭代器

    for循环的数据类型: 1.集合数据类型,如list列表,tuple元组,dict字典,set集合,str字符串等: 2.generator生成器,包括生成器和带yield的generator fun ...

  7. Unicode字符集和编码方式

    通常将一个标准中能够表示的所有字符的集合称为字符集,比如ISO/Unicode所定义的字符集为Unicode.在Unicode中,每个字符占据一个码位/Unicode 编号(用4位十六进制数表示,Co ...

  8. 笔记本shift变粘贴,粘滞键设置已关闭

    之前手贱吧,拿湿抹布擦了擦笔记本电脑的自带键盘,然后部分按键失灵了. 本想着反正也都是在寝室用的,趁机找借口买了个机械键盘,啪啪啪... 刚开始好好的,后来发现一按shift就会粘贴,百度了下都说是粘 ...

  9. Redis多实例及主从搭建

    主从搭建前提是服务器上已经安装好了redis, redis安装可搜索本站另一篇博客:redis安装. redis单主机多实例 一.我们首先拷贝两份文件: cp /etc/redis.conf /etc ...

  10. JVM-1.编译

    目录 一.编译器概述 二.编译器组成 三.示例 四.深入理解JVM中的编译器 五.语法糖 六.补充     一.编译器概述 1.编译器实质 编译器的实质是将一种语言规范转化为另一种语言规范:由人容易理 ...