[leetcode] 495. Teemo Attacking
来源:互联网 发布:百度seo排名公司 编辑:程序博客网 时间:2024/05/24 15:39
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], 2Output: 4Explanation: 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], 2Output: 3Explanation: 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:
- You may assume the length of given time series array won't exceed 10000.
- 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.
这道题是计算Teemo释放的毒药在敌人身上持续的总时间,题目难度为Medium。
题目描述蛮唬人的,其实只需要判断是否刷新毒药持续时间就行了。如果毒药效果消失前进行了下一次攻击则刷新毒药持续时间,否则毒药效果消失。具体代码:
class Solution {public: int findPoisonedDuration(vector<int>& timeSeries, int duration) { if(timeSeries.empty() || duration == 0) return 0; int total = duration; for(int i=0; i<timeSeries.size()-1; ++i) { int gap = timeSeries[i+1] - timeSeries[i]; if(gap < duration) total += gap; else total += duration; } return total; }};
0 0
- 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 解题报告
- Intellij idea2016创建Maven的web项目
- 微信企业号自建应用
- ArrayBlockingQueue
- solr智能提示 suggest(针对索引的某个字段建立索引词库做智能提示)
- C# 获取文件名,路径
- [leetcode] 495. Teemo Attacking
- linux中struct class
- VS2015程序出现缺少dll文件解决方法
- HashTable与HashMap的区别
- Spring Boot 定时任务的使用
- Visual C#中操作WMI的类库简介
- Jquery对象动画方法总结
- 企业构建大数据分析体系的4个层级
- 《算法第四版》环境搭建