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

    按要求连边,跑匈牙利 #include<algorithm> #include<iostream> #include<cstdlib> #include<cs ...

  2. FAT和FAT32文件系统的原理

    [转自] http://www.sjhf.net/Article/sjhfdoc/200404/1.html 一.硬盘的物理结构:     硬盘存储数据是根据电.磁转换原理实现的.硬盘由一个或几个表面 ...

  3. ElementUI的Upload上传,配合七牛云储存图片

    七牛云服务器的储存区域 存储区域 地域简称 上传域名 华东 z0 服务器端上传:http(s)://up.qiniup.com 华东 z0 客户端上传: http(s)://upload.qiniup ...

  4. HDU4283 You Are the One —— 区间DP

    题目链接:https://vjudge.net/problem/HDU-4283 You Are the One Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. LR工作原理

    LoadRunner的总体架构图,包括各个组件VUGen, Controller和Analysis之间的关系. LoadRunner由四大组件组成:VuGen.控制器.负载发生器和分析器. 1.VuG ...

  6. close() was never explicitly called on database

    在用SQLiteDatabase的时候如果碰到说database或者cursor没有关闭,可以在使用完之后加上: if (!cursor.isClosed()) { cursor.close(); } ...

  7. Objective-C中的+initialize和+load

    写在前面 近几天花了一些时间了解了一下Objective-C runtime相关的东西,其中涉及到了+load方法,譬如method swizzling通常在category的+load方法中完成.之 ...

  8. 【HDU 3555】 Bomb

    [题目链接] 点击打开链接 [算法] 数位DP [代码] #include<bits/stdc++.h> using namespace std; #define MAXL 15 type ...

  9. "standard,singleTop,singleTask,singleInstance"-Android启动模式

    安卓有4种启动模式,下面我们就进行详细的讲解 用栈的思维去理解,就能理解这些启动模式的本质了 先设置两个页面: A(为测试对象),B两个页面,两个页面都有跳至对方的按钮 一.标准模式(standard ...

  10. 中文环境下PostgreSQL的使用

    虽然官方文档有提到编码的问题,但是对于中文讲的比较简单,给中文的PostgreSQL用户带来很多困扰,本文简单简述一下中文环境下PostgreSQL如何正确设置编码. 一.服务器端的编码设置 Post ...