java easy to understand!


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

Log in to reply
 

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