O(n) C Solution


  • 0
    S
    int findMaxConsecutiveOnes(int* nums, int numsSize) {
        int i=0, curCount=0, maxCount=0;
        do{
            if(nums[i]==1){
                curCount++;
                if(curCount>maxCount){
                    maxCount=curCount;
                }
            }
            else{
                curCount=0;
            }
            
             
            i++;
        }while(i<numsSize);
        
        return maxCount;
    }
    

Log in to reply
 

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