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.

原文地址

题解

挺有意思的,LeetCode竟然出了一题关于提莫大魔王的题目,看来英雄联盟真是火遍全世界啊。
题目大意是:
提莫大魔王与艾希(寒冰射手)对A,提莫可以致盲,每次致盲会有一个持续时间,致盲时间不叠加(要是叠加那主Q对面不是没得玩了),在致盲的过程中如果继续致盲,那么致盲的时间将从现在开始计算。

根据这个方案,我们可以直接扫描一次数组,计算两次间隔时间差,如果这个时间差在致盲的持续范围内,那么我们就取这个时间差,如果不在我们就可以取致盲的持续时间

代码

 public static int findPoisonedDuration(int[] timeSeries, int duration) {int ret = 0;for (int i = 0; i < timeSeries.length; i++) {if (i > 0 && timeSeries[i] - timeSeries[i - 1] < duration) {ret += timeSeries[i] - timeSeries[i - 1];} else {ret += duration;}}return ret;}

题解2️⃣

之前的那种方式是正向的,这次来逆向的,我们先计算总的中毒持续时间,即数组位数*持续时间,然后跟之前一样,当出现冲突,即两次中毒时间小于持续时间,我们减去即可。

代码

public int findPoisonedDuration(int[] timeSeries, int duration) {  int ret= timeSeries.length * duration;  for(int i=1; i<timeSeries.length; i++) {  if(timeSeries[i] - timeSeries[i-1] < duration) {  result -= duration - (timeSeries[i] - timeSeries[i-1]);  }  }  return ret;
}  

【LeetCode】495. Teemo Attacking(提莫大魔王)相关推荐

  1. LeetCode 495. Teemo Attacking

    题意:在LLP的世界里,有个英雄叫Teemo,他的攻击能使他的敌人Ashe处理中毒状态.现在,给出Teemo的攻击序列和每次攻击的中毒持续时间,输出Ashe中毒的总共时间. 思路:根据每次攻击时间,可 ...

  2. 495. Teemo Attacking

    495. Teemo Attacking 标签(空格分隔): leetcode array medium 题目 In LOL world, there is a hero called Teemo a ...

  3. leetcode 495.提莫攻击

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

  4. LeetCode 495. 提莫攻击

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

  5. leetcode:495. 提莫攻击

    题目 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/teemo-attacking 在<英雄联盟>的世界中,有一个叫 " ...

  6. Java实现 LeetCode 495 提莫攻击

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

  7. [LeetCode]495. 提莫攻击

    题目描述 在<英雄联盟>的世界中,有一个叫 "提莫" 的英雄.他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态. 当提莫攻击艾希,艾希的中毒状态正好持续 du ...

  8. Leetcode 495:提莫攻击

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

  9. LeetCode 495. 提莫攻击 解答

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

最新文章

  1. ecshop安装linux7,RedHat下如何搭建ecshop?
  2. php 微信开发 菜单,微信公众号中个性化菜单的开发实例
  3. 关于Java的十件事
  4. ubuntu server 12.04 jdk,ssh及hadoop配置
  5. MySQL(8)--- 选择数据库
  6. Visual SVN的安装
  7. CSS 布局 - Overflow
  8. python在webservice接口测试中的应用
  9. c语言程序设计万年历的显示,C语言程序设计万年历
  10. 使用Redis Desktop Manager连接Redis服务器
  11. mysql ip 访问_MySql通过ip地址进行访问的方法
  12. 没有第三个变量的前提下交换两个变量_很多人连Python变量都没搞懂,说自己会python
  13. 使用LoadRunner进行性能测试的简单步骤
  14. matlab中面板数据格式,MATLAB空间面板数据模型操作介绍
  15. uniapp 引用图片地址
  16. opencv制作微信小游戏 最强连一连 辅助(2)--dfs深度优先搜索算法
  17. php word组件使用方法,phpword使用笔记
  18. c语言文字冒险类游戏,课内资源 - 基于C语言和easyx实现的巧虎划船大冒险游戏...
  19. ArcGIS学习05:坐标系
  20. 异步爬虫“该文章已下线” 、“mrd参数”解决方法

热门文章

  1. 《记事本成功法》 凡禹
  2. php执行md5sum,Linux_详解Linux系统中md5sum命令的用法,MD5算法常常被用来验证网络文 - phpStudy...
  3. 打印机怎么连接电脑?您只需要这样做!
  4. Android AnnotationProcessor
  5. 申论真题模考及参考答案
  6. 新玺配资:量能不足但元宇宙却像一匹脱缰野马
  7. 串口通讯数据接收代码
  8. CSK与KCF算法推导(三)
  9. 大数据任务调度工具azkaban初步使用
  10. HTML5新特性总结大全