Easy Java solution


  • 0
    Q

    A straightforward JAVA solution.

    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            int answer = 0;
            if(timeSeries.length == 0) return answer;
            for(int i = 0; i < timeSeries.length - 1; i++) {
                int time = timeSeries[i + 1] - timeSeries[i];
                answer += (time >= duration) ? duration : time;//the duration time depends on the next attack
            }
            return answer + duration;//add the last duration time
        }
    }

Log in to reply
 

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