In LOL 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.

计算中毒的总时间

C++(74ms):

 class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
int len = timeSeries.size() ;
if (len < )
return ;
int sum = ;
for(int i = ; i < len- ; i++){
if (timeSeries[i+] - timeSeries[i] < duration){
sum += timeSeries[i+] - timeSeries[i] ;
}else{
sum += duration ;
}
}
sum += duration ;
return sum ;
}
};

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

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

  5. [LeetCode] Teemo Attacking 提莫攻击

    In LLP 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. 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. LeetCode Questions List (LeetCode 问题列表)- Java Solutions

    因为在开始写这个博客之前,已经刷了100题了,所以现在还是有很多题目没有加进来,为了方便查找哪些没加进来,先列一个表可以比较清楚的查看,也方便给大家查找.如果有哪些题目的链接有错误,请大家留言和谅解, ...

  9. LeetCode数组解题模板

    一.模板以及题目分类 1.头尾指针向中间逼近 ; ; while (pos1<pos2) { //判断条件 //pos更改条件 if (nums[pos1]<nums[pos2]) pos ...

随机推荐

  1. JS中的匿名函数自执行、函数声明与函数表达式

    先看一段jQuery源码中匿名函数自执行的例子: (function( window, undefined ) { // jquery code })(window); 另外一种常见的写法: +fun ...

  2. CF864 E DP 输出路径

    n个物品有Deadline,拿物品需要花费时间,问取得最大价值的方案. 本质是个01背包,先按时间排序,然后把花费的时间作为背包就行了. 主要就是找方案,倒过来找发生转移的就行了. 太菜了真的不会打C ...

  3. 本地文件夹如何断开svn连接

    最近遇到一个问题,svn的项目down失败,一不小心点了删除准备重新上传,发现本地的文件已有svn源信息,提交更新均报再找不到此文件路径. 于是想着删除此文件夹的svn信息,经过一番百度,以下方法测试 ...

  4. User-Agent大全

    一.基础知识篇: Http Header之User-Agent User Agent中文名为用户代理,是Http协议中的一部分,属于头域的组成部分,User Agent也简称UA.它是一个特殊字符串头 ...

  5. JVM调优总结(4):分代垃圾回收

    为什么要分代 分代的垃圾回收策略,是基于这样一个事实:不同的对象的生命周期是不一样的.因此,不同生命周期的对象可以采取不同的收集方式,以便提高回收效率. 在Java程序运行的过程中,会产生大量的对象, ...

  6. python 文字转语音包pyttsx安装出错解决方法

    pyttsx的python的文字转语音的包,但是pyttsx的官方网站上资源只更新2012年,所以在py3中使用pip install pyttsx或者下载安装包进行安装时,虽然可以安装成功,但是im ...

  7. max-device-width和max-width的区别

    比如用媒体查询响应输出@media (max-width: 767px),用谷歌浏览器手机测试插件显示并无变化,其实关键在于max-device-width和max-width,以下摘抄↓ max-d ...

  8. Network File System

    Network File System 2014-12-31 #system 接着上一篇博客Distributed Systems 分布式系统来扯淡,之前的博客一再在写文件系统,这次继续,只不过是分布 ...

  9. asp.net实现access数据库分页

    最近在编程人生上看到篇文章很有感触,觉得人生还是要多奋斗.今天给大家贡献点干货. <divclass="page"id="ctrlRecordPage"& ...

  10. Redhat 7 之 Mariadb(mysql)

    Redhat7 之后mysql 改为Mariadba,由于mysql 被卖给了IBM, 有闭源的风险. 所以就另外开了一个新的分支,继续开源.Maria 来源于mysql开发者的女儿的名字. 1. 安 ...