【模拟】力扣495(Java)

题目
【模拟】力扣495(Java)_第1张图片

class Solution {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int ret = 0;
        // 1 4 5 6 12 19 d = 3
        // 3 1 1 3 3 + 3
        // 11+3
        
        for(int i=1;i<timeSeries.length;i++)
        {
            int x = timeSeries[i] - timeSeries[i-1];
            if(x>=duration) ret+=duration;
            else    ret+=x;
        }
        return ret+duration;
    }
}

你可能感兴趣的:(模拟,leetcode,java,算法)