[C Solution] Simple O(n)


  • 0
    N
    int findPoisonedDuration(int* a, int n, int t) {
        int current = 0, next = 0, time = 0;
        for(int i = 0; i < n; i++){
            current = a[i];
            if(next <= current){
                next = current + t;
                time += t;
            }
            else {
                time += (t - (next - current));
                next = current + t;
            }   
        }
        return time;
    }
    

Log in to reply
 

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