Leetcode # 495 Javascript

pimkle發表於2018-11-27

Original

/**
 * @param {number[]} timeSeries
 * @param {number} duration
 * @return {number}
 */
var findPoisonedDuration = function(timeSeries, duration) {
    let total = 0;
    let len = timeSeries.length;
    if(!len){
        return 0;
    }
    for(let i = 0; i < len - 1; ++i){
        total += (timeSeries[i] + duration < timeSeries[i + 1] ? duration : timeSeries[i + 1] - timeSeries[i]);
    }
    total += duration;
    return total;
};
複製程式碼

相關文章