share my simple java solution!


  • 0
    T
    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
             if(timeSeries==null || timeSeries.length<1) return 0;
             
             int count=0;
             int start=0;
             while(start<timeSeries.length){
                int pre_start=start;
                while(start<timeSeries.length-1 && timeSeries[start]+duration>=timeSeries[start+1]){
                    start++;
                }
                count+=timeSeries[start]-timeSeries[pre_start]+duration;
                start++;
             }
             
             return count;
        }
    }
    

Log in to reply
 

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