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 题目讲解汇总(持续更新中...)

最新文章

  1. Linux Crontab语法
  2. x01.Weiqi.8: 一点改进
  3. java 内部类与外部类的区别
  4. DBA应用技巧:如何升级InnoDB Plugin
  5. Java学习笔记(五)&mdash;&mdash;数组
  6. centos下安装mysql步骤
  7. 参照openRTSP写的一个RTSP client 加了一些注解
  8. HDU 2852 KiKi&#39;s K-Number
  9. Android开发——Toast知识
  10. MySQL MERGE存储引擎
  11. Unable to docker login through CLI - unauthorized: incorrect username or password
  12. 【XSY1551】往事 广义后缀数组 线段树合并
  13. svn介绍
  14. k8s 实验过程中遇到的两个小问题 端口 和 批量删除Error的pods
  15. mysql 主从同步遇到的问题(1032)
  16. 信息安全系统设计基础_exp1
  17. Google题解
  18. poj1981 Circle and Points
  19. LG4169 [Violet]天使玩偶/SJY摆棋子
  20. Spring : JPA的单独使用

热门文章

  1. Leetcode 2——Range Sum Query - Mutable(树状数组实现)
  2. oracle数据库修改连接数
  3. C语言程序设计(基础)- 第3周作业
  4. 网络1711班 C语言第一次作业批改总结
  5. 敏捷冲刺每日报告——Day2
  6. 学号:201621123032 《Java程序设计》第9周学习总结(
  7. RxSwift:ReactiveX for Swift 翻译
  8. vue class与style 绑定详解——小白速会
  9. Python扩展模块——调用WindowsAPI(pywin32的简单使用)
  10. 【ASP.NET Core】依赖注入高级玩法——如何注入多个服务实现类