Teemo Attacking
来源:互联网 发布:q3 1.4t 2.0t 知乎 编辑:程序博客网 时间:2024/06/05 22:45
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.
这道题,采用的是分情况给sum加值的方法,当数组中,timeSeries[i]+duration<=timeSeries[i+1]时,就直接加sum+=duration;,因为有足够的时间让这一枪的毒充分的延迟,对于其他非最后一个数组元素的情况,都是只要加上前后2个时间点的差就可以了。
代码如下:
class Solution {public: int findPoisonedDuration(vector<int>& timeSeries, int duration) { int sum=0; int size=timeSeries.size(); for(int i=0;i<size;i++){ if(size==1){ sum+=duration; return sum; } else if(size>=2){ if(i!=size-1){ if(timeSeries[i]+duration<=timeSeries[i+1]){ sum+=duration; } else{ sum+=(timeSeries[i+1]-timeSeries[i]); } } else{ sum+=duration; } } } return sum; }};
0 0
- Teemo Attacking
- Teemo Attacking
- Teemo Attacking
- LeetCode题解:Teemo Attacking
- 495. Teemo Attacking
- LeetCode 495. Teemo Attacking
- LeetCode: 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
- [Array]495. Teemo Attacking
- Leetcode 495 Teemo Attacking
- leetcode495 Teemo Attacking Java
- 用自己写的ImageLoad实现照片墙
- CCF消除类游戏
- thinkphp3.2.3 重命名默认模块名 和 新建模块
- Javascrit通过百度地图API获取客户端IP、地址
- TensorFlow学习系列(四):利用神经网络实现泛逼近器(universal approximator)
- Teemo Attacking
- pycharm配置
- tarjan算法
- 数值的整数次方
- TensorFlow学习系列(五):如何使用队列和多线程优化输入管道
- JMeter 中Random 随机函数的使用
- 【分享】京东分布式数据库系统演进之路
- TensorFlow学习系列(六):变量更新和控制依赖
- pycharm cannot find reference xxx in init_.py 的一个解决方案