题目讲解
495. 提莫攻击
算法讲解
前后的两个数字之间的关系要么是相减之差 >= 中毒时间 ,要么反之
那即可通过示例,进行算法的模拟,得出上图的计算公式
class Solution {
public:int findPoisonedDuration(vector<int>& timeSeries, int duration) {if(timeSeries.size() == 1)return duration;int ret = duration;for(int i = 0; i < timeSeries.size()-1; i++){if(timeSeries[i+1] - timeSeries[i] >= duration)ret += duration;else ret += timeSeries[i+1] - timeSeries[i];}return ret;}
};