O(n) Java Solution


  • 4
    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            int res=0;
            if(timeSeries==null||timeSeries.length==0||duration<=0) return res;
            for(int i=1;i<timeSeries.length;i++){
                res+=Math.min(duration, timeSeries[i]-timeSeries[i-1]);
            }
            return res+duration;
        }
    }
    

Log in to reply
 

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