[JAVA] Update pre time and compare with current time. / T : O(N), S:O(1)


  • 0
    J
    class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            int pre = -1;
            int sum = 0;
            for(int time : timeSeries){
                sum += duration;
                if(pre >= time){
                    sum -= (pre - time + 1);
                }
                pre = duration + time - 1;
            }
            
            return sum;
        }
    }
    

Log in to reply
 

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