Frank's Java solution O(n)


  • 0
    F
    class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            int out = 0, end = 0;
            for (int i=0; i<timeSeries.length; i++) {
                out += timeSeries[i] > end ? duration : timeSeries[i] + duration - end;
                end = timeSeries[i] + duration;
            }
            return out;
        }
    }
    

Log in to reply
 

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