It does not deserve a Medium difficulty, is it?


  • 0
    H

    As title, it's very straightfoward, isn't it?

    BTW, my simple JavaScript solution.

    /**
     * @param {number[]} timeSeries
     * @param {number} duration
     * @return {number}
     */
    var findPoisonedDuration = function(timeSeries, duration) {
      let ans = 0;
    
      for (let i = 0, len = timeSeries.length; i < len; i++) {
        if (i === len - 1) {
          ans += duration;
          continue;
        }
    
        let curItem = timeSeries[i]
          , nextItem = timeSeries[i + 1];
    
        if (curItem + duration <= nextItem)
          ans += duration;
        else
          ans += nextItem - curItem;
      }
    
      return ans;
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.