Easy to understand Java solution


  • 0
    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            if(timeSeries.length == 0) return 0;
            if(timeSeries.length == 1) return duration;
            int time = 0;
            int startTime = timeSeries[0];
            for(int i = 1; i < timeSeries.length; ++i) {
                if(timeSeries[i]-startTime >= duration) {
                    time+=duration;
                }
                else{
                    time+=(timeSeries[i]-startTime);
                }
                startTime = timeSeries[i];
            }
            time+=duration;
            return time;
        }
    }
    

Log in to reply
 

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