Java III


  • 0
    G
      public int findPoisonedDuration(int[] timeSeries, int duration) {
            int i=0, len = timeSeries.length, poisoned = 0;
            //Get the minimum of overlapped time
            while(++i < len) poisoned += Math.min(timeSeries[i] - timeSeries[i-1], duration);
            
            return (len > 0) ? poisoned + duration : 0; //as long as Teemo attacked once add the duration for the last spell
        }
    

    III 3 line solution!


Log in to reply
 

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