leetcode 495. Teemo Attacking
来源:互联网 发布:mac 视频特效 编辑:程序博客网 时间:2024/06/11 05:08
1.题目
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.
英雄Teemo对敌人 Ashe 使用毒药会使敌人中毒一段时间。
给出一个时间序列timeSeries表示英雄对敌人使用毒药的时间点,duration表示毒药的持续时间。求敌人总共有多长时间保持中毒状态。
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
4-1>2 所以 2+2=4
Example 2:
Input: [1,2], 2
Output: 3
(2-1)+2=3
2.分析
判断两个使用毒药的时间间隔delta
delta>= duration, 持续时间+=duration
delta< duration, 持续时间+=delta
3.代码
class Solution {public: int findPoisonedDuration(vector<int>& timeSeries, int duration) { if(timeSeries.size()<1) return 0; int count = duration; for (int i = 1; i < timeSeries.size(); i++) count += timeSeries[i] - timeSeries[i - 1] >= duration ? duration : timeSeries[i] - timeSeries[i - 1]; return count; }};
- LeetCode 495. Teemo Attacking
- LeetCode 495. Teemo Attacking
- LeetCode:495. Teemo Attacking
- 【Leetcode】495. Teemo Attacking
- [leetcode] 495. Teemo Attacking
- leetcode 495. Teemo Attacking
- 【LeetCode】495. Teemo Attacking
- LeetCode 495. Teemo Attacking
- LeetCode 495. Teemo Attacking
- leetcode 495. Teemo Attacking
- leetcode 495. Teemo Attacking
- [LeetCode] 495. Teemo Attacking
- leetcode 495. Teemo Attacking
- leetcode 495. Teemo Attacking
- 【LeetCode】495. Teemo Attacking【M】【41】
- 【数组】Leetcode编程题解:495. Teemo Attacking
- 【LeetCode】495.Teemo Attacking解题报告
- [Leetcode] 495. Teemo Attacking 解题报告
- c语言---const搭配指针问题
- 从源程序到可执行程序
- 【Python】pip install windows下报ascii无法编码
- JavaWeb项目,使用ajax进行访问Url,依然请求是上个请求地址
- [5] Spring中的AOP操作(使用xml 配置文件的方式)
- leetcode 495. Teemo Attacking
- makefile 工具基本使用(2)
- 顺序表的操作
- CNN(卷积神经网络)
- 戒色
- 非极大值抑制(Non-maximum suppression, NMS)
- LeetCode#121. Best Time to Buy and Sell Stock
- 打印对象和toString方法
- 帅哥陈爬虫笔记ppppython(1),我也不知道起个什么题目