Simply Java one pass solution


  • 0
    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            int total = 0, currentEnd = Integer.MIN_VALUE;
            for (int time : timeSeries) {
                if (time >= currentEnd) {
                    total += duration;
                } else {
                    total += time + duration - currentEnd;
                }
                currentEnd = time + duration;
            }
            return total;
        }
    }
    

Log in to reply
 

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