在《英雄联盟》的世界中,有一个叫“提莫”的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态。现在,给出提莫对艾希的攻击时间序列和提莫攻击的中毒持续时间,你需要输出艾希的中毒状态总时长。
你可以认为提莫在给定的时间点进行攻击,并立即使艾希处于中毒状态。
示例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 提莫攻击的更多相关文章

  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] Teemo Attacking 提莫攻击

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

  3. LeetCode 495. 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. Teemo Attacking 解题报告(Python & C++)

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

  5. 495. Teemo Attacking

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

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

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

  7. Java实现 LeetCode 495 提莫攻击

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

  8. [Leetcode]495.提莫攻击

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

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

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

随机推荐

  1. Tomcat安全配置规范

    第1章 账号管理.认证授权 1.1 账号 1.1.1 共享帐号管理 安全基线项目名称 Tomcat共享帐号管理安全基线要求项 安全基线编号 SBL-Tomcat-01-01-01 安全基线项说明   ...

  2. Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP

    E. Liar     The first semester ended. You know, after the end of the first semester the holidays beg ...

  3. split+ Pattern切割字符串

    今天在对一个String对象进行拆分的时候,总是无法到达预计的结果.呈现数据的时候出现异常,后来debug之后才发现,错误出在String spilt上,于是开始好好研究下这东西,开始对api里的sp ...

  4. 在Qt Creator中为Qt工程添加资源

    1.右键单击工程 -> Add New ... -> Qt -> Qt Resource File -> Choose... -> Name: -> Next -& ...

  5. !important的用法(IE6 兼容的解决方法)

    我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义 < 元素style中的属性,但是如果使用!important,事情就会变得不一样. 首先,先看下面一段代码: <!DO ...

  6. css3的渐变效果

    1.css3 渐变的属性 例子: #grad { background: -webkit-linear-gradient(red, blue); /* Safari 5.1 - 6.0 */ back ...

  7. express 中文文档

    express() 创建一个express应用程序 var express = require('express'); var app = express(); app.get('/', functi ...

  8. hdu 超级楼梯 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041 哦--对了,这些题读者可以直接忽略,我只是想练习一下自己薄弱的地方...... 题目意思我就不说 ...

  9. windwo访问linux文件夹方法

    windwo访问linux文件夹:是通过linux的samba来实现的: 安装samba需要安装samba-client.samba-common.smaba3个包. 一:安装rpm 现有一个服务器l ...

  10. codeforces 667C C. Reberland Linguistics(dp)

    题目链接: C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes inpu ...