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.

Note:

  1. You may assume the length of given time series array won't exceed 10000.
  2. You may assume the numbers in the Teemo's attacking time series and his poisoning time duration per attacking are non-negative integers, which won't exceed 10,000,000.

LeetCode果然花样百出,连提莫都搬上题目了,那个草丛里乱种蘑菇的小提莫,那个“团战可以输提莫必须死”的提莫??可以,服了,坐等女枪女警轮子妈的题目了~好了,不闲扯了,其实这道题蛮简单的,感觉不能算一道medium的题,就直接使用贪心算法,比较相邻两个时间点的时间差,如果小于duration,就加上这个差,如果大于或等于,就加上duration即可,参见代码如下:

class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
if (timeSeries.empty()) return ;
int res = , n = timeSeries.size();
for (int i = ; i < n; ++i) {
int diff = timeSeries[i] - timeSeries[i - ];
res += (diff < duration) ? diff : duration;
}
return res + duration;
}
};

LeetCode All in One 题目讲解汇总(持续更新中...)

[LeetCode] Teemo Attacking 提莫攻击的更多相关文章

  1. 495 Teemo Attacking 提莫攻击

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

  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. [Swift]LeetCode495. 提莫攻击 | Teemo Attacking

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

  4. [Leetcode]495.提莫攻击

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

  5. Java实现 LeetCode 495 提莫攻击

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

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

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

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

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

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

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

  9. 495. Teemo Attacking

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

随机推荐

  1. Jquery判断checkbox是否被选中

    jQuery中: $("input[type='checkbox']").is(':checked') 返回true或false 1.attr()方法  设置或者返回备选元素的值 ...

  2. Jupyter Notebook的快捷键

    Jupyter Notebook 有两种键盘输入模式. 编辑模式,允许你往单元中键入代码或文本,这时的单元框线是绿色的. 命令模式,键盘输入运行程序命令:这时的单元框线是蓝色.       命令模式 ...

  3. Socket程序从windows移植到linux下需要注意的

    )头文件 windows下winsock.h或winsock2.h linux下netinet/in.h(大部分都在这儿),unistd.h(close函数在这儿),sys/socket.h(在in. ...

  4. 开启Linux的share

    1.挂载Install  Vmare Tool 2.解压VMwareTools.tar.gz 3.安装share目录 4.shared Folders Enabled 添加共享的目录. 在自己的Unb ...

  5. Linux下I/O多路转接之select --fd_set

    fd_set 你终于还是来了,能看到这个标题进来的,我想,你一定是和我遇到了一样的问题,一样的疑惑,接下来几个小时,我一定竭尽全力,写出我想说的,希望也正是你所需要的: 关于Linux下I/O多路转接 ...

  6. Cypher语法

    cypher是neo4j官网提供的声明式查询语言,非常强大,用它可以完成任意的图谱里面的查询过滤,我们知识图谱的一期项目 基本开发完毕,后面会陆续总结学习一下neo4j相关的知识.今天接着上篇文章来看 ...

  7. bzoj千题计划271:bzoj4869: [六省联考2017]相逢是问候

    http://www.lydsy.com/JudgeOnline/problem.php?id=4869 欧拉降幂+线段树,每个数最多降log次,模数就会降为1 #include<cmath&g ...

  8. LoadRunner录制手机APP教程

    1.     开启fiddler 2.     打开HP Virtual User Generator,新建->Web (HTTP/HTML)>创建 3.     点击开始录制: (1) ...

  9. 在ArcGIS中导出现有mxd的style文件

     做好的地图包含许多地图符号,这是之前花了很多功夫做的,怎么把它导出来再用呢?     在ArcGIS中右键工具栏,customize,选择command选项卡,在搜索框中输入style ,选择too ...

  10. python 一篇搞定所有的异常处理

    一:什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在python无法正常处理程序时就会发生一个异常(异常是python对象,表示一个错误) 异常就是 ...