Java实现 LeetCode 495 提莫攻击
495. 提莫攻击
在《英雄联盟》的世界中,有一个叫 “提莫” 的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态。现在,给出提莫对艾希的攻击时间序列和提莫攻击的中毒持续时间,你需要输出艾希的中毒状态总时长。
你可以认为提莫在给定的时间点进行攻击,并立即使艾希处于中毒状态。
示例1:
输入: [1,4], 2
输出: 4
原因: 在第 1 秒开始时,提莫开始对艾希进行攻击并使其立即中毒。中毒状态会维持 2 秒钟,直到第 2 秒钟结束。
在第 4 秒开始时,提莫再次攻击艾希,使得艾希获得另外 2 秒的中毒时间。
所以最终输出 4 秒。
示例2:
输入: [1,2], 2
输出: 3
原因: 在第 1 秒开始时,提莫开始对艾希进行攻击并使其立即中毒。中毒状态会维持 2 秒钟,直到第 2 秒钟结束。
但是在第 2 秒开始时,提莫再次攻击了已经处于中毒状态的艾希。
由于中毒状态不可叠加,提莫在第 2 秒开始时的这次攻击会在第 3 秒钟结束。
所以最终输出 3。
注意:
你可以假定时间序列数组的总长度不超过 10000。
你可以假定提莫攻击时间序列中的数字和提莫攻击的中毒持续时间都是非负整数,并且不超过 10,000,000。
PS:
这个题让我很有动力,
(ง •_•)ง
class Solution {
public int findPoisonedDuration(int[] timeSeries, int duration) {
int count = 0;
for (int i = 1; i < timeSeries.length; i++)
count += timeSeries[i] - timeSeries[i - 1] > duration ? duration : timeSeries[i] - timeSeries[i - 1];
return timeSeries.length == 0 ? 0 : count + duration;
}
}
Java实现 LeetCode 495 提莫攻击的更多相关文章
- [Leetcode]495.提莫攻击
题目: 在<英雄联盟>的世界中,有一个叫 "提莫" 的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态.现在,给出提莫对艾希的攻击时间序列和提莫攻击的中 ...
- 495 Teemo Attacking 提莫攻击
在<英雄联盟>的世界中,有一个叫“提莫”的英雄,他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态.现在,给出提莫对艾希的攻击时间序列和提莫攻击的中毒持续时间,你需要输出艾希的中毒 ...
- [Swift]LeetCode495. 提莫攻击 | Teemo Attacking
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...
- Java for LeetCode 216 Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- Java for LeetCode 214 Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- Java for LeetCode 212 Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- Java for LeetCode 211 Add and Search Word - Data structure design
Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...
- Java for LeetCode 210 Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- Java for LeetCode 200 Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
随机推荐
- springboot controller templates html
首先声明: @Controller注解的类必须要在启动类的子集目录下,否则无法扫描 本文要求: 通过controller层跳转页面到html页面(本篇用到thymeleaf模板) 项目结构展示: 第一 ...
- (1)从通信中的MCS含义开始讲起
通信中的MCS:Modulation and Coding Scheme,意思为调制编码方案/调制编码策略,其内涵可分为两个部分:Modulation 和 Coding. 在基带的信号处理流程中, ...
- 设计模式之GOF23外观模式
外观模式 迪米特原则:一个软件实体应当尽可能少的与其他实体发生相互作用 外观模式核心:为子系统提供统一的入口,封装子系统的复杂性,便于客户端调用 相当于找了个代理帮你做了所有事而你只需要和代理打交道
- Spark SQL源码解析(四)Optimization和Physical Planning阶段解析
Spark SQL原理解析前言: Spark SQL源码剖析(一)SQL解析框架Catalyst流程概述 Spark SQL源码解析(二)Antlr4解析Sql并生成树 Spark SQL源码解析(三 ...
- Mysql常用sql语句(20)- 子查询重点知识
测试必备的Mysql常用sql语句系列 https://www.cnblogs.com/poloyy/category/1683347.html 子查询语句可以嵌套在 sql 语句中任何表达式出现的位 ...
- go多种uuid生成方式
package main import ( "fmt" "github.com/chilts/sid" "github.com/kjk/betterg ...
- python之unittest验证函数功能
一.待验证脚本 首先,有如下三个脚本,分别对应三个函数 分别导入模块行,如下: from fuction1 import fu1 from fuction2 import fu2 from fucti ...
- gets() 、 getchar() 、 getch() 、getche()、gets()、 scanf()的区别
1.getchar().getche().getch() (1).getchar 函数用于从标准输入设备键盘读入单个字符,返回表示读入字符的ASCII码值,并在屏上显示该字符:头文件是 stdio.h ...
- Linux -- 在文件中添加信息的方法(转)
转自:https://www.cnblogs.com/ZGreMount/p/7645542.html 创建test 文件: touch test.txt 方法一:echo 命令法: echo &qu ...
- Java并发II
Java并发 J.U.C图 一.线程的安全性 当多个线程访问某个类的时候,不管运行环境采用何种方式调度或者这些线程如何交替执行,并且在主调代码中不需要任何额外的同步或者协同,这个类都可以表现出正确的行 ...