leetcode 495. Teemo Attacking
2017-06-25 15:32
453 查看
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.分析
判断两个使用毒药的时间间隔deltadelta>= 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; } };
相关文章推荐
- leetcode495 Teemo Attacking Java
- [LeetCode] 495. Teemo Attacking
- LeetCode 495. Teemo Attacking
- leetcode题解-566. Reshape the Matrix && 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
- LeetCode 495. Teemo Attacking 题目翻译+AC代码
- 【LeetCode】495. Teemo Attacking 解题报告(Python)