[Array]495.Teemo Attacking
来源:互联网 发布:数据分析 培训 上海 编辑:程序博客网 时间:2024/06/18 11:27
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.
Solution
class Solution {public: int findPoisonedDuration(vector<int>& timeSeries, int duration) { int size = timeSeries.size(); int i=0, j=0, tmpSum = duration, totalSum=0; while (i<size){ tmpSum += timeSeries[i]; for (j=i+1;j<size;j++){ if (tmpSum>=timeSeries[j]) { tmpSum = timeSeries[j]+duration; } else{ break; } } totalSum += (tmpSum-timeSeries[i]); cout << "totalSum:" << totalSum<< endl; i = j; tmpSum=duration; } return totalSum; }};
0 0
- [Array]495. Teemo Attacking
- [Array]495.Teemo Attacking
- 1.1 Array 495.Teemo Attacking
- LeetCode|Array|Teemo Attacking
- LeetCode Array Problem || Teemo Attacking
- 495. Teemo Attacking
- LeetCode 495. Teemo Attacking
- LeetCode 495. Teemo Attacking
- 495. Teemo Attacking
- 495. Teemo Attacking
- 495. Teemo Attacking
- LeetCode:495. Teemo Attacking
- 【Leetcode】495. Teemo Attacking
- 495. Teemo Attacking
- 495. Teemo Attacking
- [leetcode] 495. Teemo Attacking
- 495. Teemo Attacking
- 495. Teemo Attacking
- QT中串口得到数值怎么把两个16进制合并成一个低八位ie,一个高八位
- 小菜鸟学习SpringMVC(三) 数据自动封装
- 前端路(6:40)
- Bricks Game(HackerRank play-game)
- 乘积最大(动态规划)
- [Array]495.Teemo Attacking
- String.format详解
- CodeForces 762A k-th divisor
- 逆转链表-pta02-线性结构3 Reversing Linked List
- 2017年ACM模板(常用)弱渣整理 四、动态规划
- CMSIS-RTOS2 应用笔记 七 构建RTX5库
- Abbreviation(HackerRank abbr)
- 什么是JS面向对象?
- TextView:图文混排