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. MySQL建表时列名同保留字重复问题解决办法

    建表时遇到遇到属性名同MySQL的保留字相同导致不能建表的问题,如下SQL语句: CREATE TABLE TBL_ACCOUNT_FROZEN_RECORD ( ID BIGINT NOT NULL ...

  2. openstack日志模块

    一.简单的python日志模块介绍 http://www.cnblogs.com/tuzkee/p/3974193.html http://blog.csdn.net/jgood/article/de ...

  3. Tensorflow Batch normalization函数

    Tensorflow Batch normalization函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 stackoverflow上tensorflow实现BN的不同函数的 ...

  4. Spring MVC 拦截器配置 -- 利用session

    spring-servlet.xml <?xml version="1.0" encoding="UTF-8"?><beans xmlns=& ...

  5. CF839 B 贪心

    很玄的一道贪心题,大意是给出k排 XX - XXXX - XX这样的座位,有n个团体,要求不同团体不能相邻而坐,中间可以空一个座位或是由走廊隔开. 很明显最先想到可以以2为单位划分座位,但是中间4连座 ...

  6. Python进行数据分析—可视化之seaborn

    安装seaborn,可以使用 pip: pip install seaborn 也可以使用 conda: conda install seaborn 一个简单的箱线图: import numpy as ...

  7. 【BZOJ】4032: [HEOI2015]最短不公共子串(LibreOJ #2123)

    [题意]给两个小写字母串A,B,请你计算: (1) A的一个最短的子串,它不是B的子串 (2) A的一个最短的子串,它不是B的子序列 (3) A的一个最短的子序列,它不是B的子串 (4) A的一个最短 ...

  8. 【CodeForces】576 C. Points on Plane

    [题目]C. Points on Plane [题意]给定坐标系中n个点的坐标(范围[0,10^6]),求一种 [ 连边形成链后总长度<=2.5*10^9 ] 的方案.n<=10^6. [ ...

  9. HDU 2082 找单词 (普通母函数)

    题目链接 Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于 ...

  10. Python面向对象学习 1 (什么是面向对象,面向对象的应用场景,待更新)

    程序设计的三种基本结构: 面向对象,面向过程,函数式编程   1,什么是面向对象编程    面向对象编程是一种编程方式,此编程方式的落地需要使用 “类” 和 “对象” 来实现,所以,面向对象编程其实就 ...