O(n) in C language


  • 0
    I

    int findMaxConsecutiveOnes(int* nums, int numsSize) {
    int max = 0, sum = 0, i = 0;

    if(numsSize == 1) return nums[0];    
    for(i = 0; i < numsSize; i++){
        if(nums[i] == 0){         
            sum = 0;
        }else{
            sum++;
        }
        if(sum > max) max = sum;
    }
    return max;
    

    }


Log in to reply
 

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