495. Teemo Attacking

不理解这道题为什么是medium= =,挺简单的,乏善可陈。

我的解法

class Solution {
public:
    int findPoisonedDuration(vector& timeSeries, int duration) {
        int output = 0;
        if (timeSeries.size() > 0){
            for (int i = 1; i < timeSeries.size(); i ++){
                output += timeSeries[i] - timeSeries[i-1] >= duration ? duration : timeSeries[i] - timeSeries[i-1] ; 
            }
            output += duration;
        }
        
        return output;
    }
};

他人解法

窃以为没自己好。

lass Solution {
public:
    int findPosisonedDuration(vector& ts, int duration) {
        int tp = 0, pe = 0;
        for(int i=0; i

你可能感兴趣的:(495. Teemo Attacking)