LeetCode 495. Teemo Attacking
来源:互联网 发布:网红淘宝 扒皮 编辑:程序博客网 时间:2024/05/17 05:11
题意:在LLP的世界里,有个英雄叫Teemo,他的攻击能使他的敌人Ashe处理中毒状态。现在,给出Teemo的攻击序列和每次攻击的中毒持续时间,输出Ashe中毒的总共时间。
思路:根据每次攻击时间,可以计算出中毒结束的时间,取中毒结束时间与下次攻击时间的最小值,可以得到每次攻击的持续时间,将这个时间相加得到中毒的总共时间。
代码如下:
var findPoisonedDuration = function(timeSeries, duration) { if (timeSeries.length === 0) return 0; var total = 0; var cur = 0, next = 0; for (var i = 0; i < timeSeries.length; i++) { cur = timeSeries[i]; next = cur + duration; if (i < timeSeries.length - 1) { var tmp = Math.min(next, timeSeries[i + 1]); total += tmp - cur; } 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 解题报告
- C++ Rvalue References Explained (c++右值引用详解)
- 蓝桥杯 带分数
- gitignore无法忽略文件,忽略文件失败
- 从OpenGL 1.x 到 2.x的迁移(即从固定管线到可编程管线的迁移)
- n^n的个位数字及求和情况
- LeetCode 495. Teemo Attacking
- linux 内存优化
- Java七种排序算法教程
- Ada and Queue
- C++编程学习52个经典网站 强力推荐
- c语言中的关键字const
- IT学习者
- 作业8:(1)超级英雄Hero
- python 各种库