Java 5 lines O(n) Simple Solution


  • 0
    Y
    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            int ans = duration;
            for (int i = 1; i < timeSeries.length; ++i) {
                ans += Math.min(duration, timeSeries[i] - timeSeries[i - 1]);
            }
            return timeSeries.length == 0 ? 0 : ans;
        }
    }
    

Log in to reply
 

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