Files
C/leetcode/src/14.c
devarshitrivedi01 55b2045b19 chore: add Max Consecutive Ones in LeetCode folder (#982)
* Create 14.c

* Update README.md

* Update leetcode/src/14.c

Co-authored-by: David Leal <halfpacho@gmail.com>

* Update DIRECTORY.md

* Update DIRECTORY.md

Co-authored-by: David Leal <halfpacho@gmail.com>
2022-11-14 12:47:23 -06:00

26 lines
448 B
C

int findMaxConsecutiveOnes(int* nums, int numsSize){
int i=0;
int maxCount=0;
int count = 0;
while(i<numsSize){
while(i<numsSize && nums[i]!=0){
count++;
i++;
}
if(maxCount<=count){
maxCount = count;
}
count = 0;
while(i<numsSize && nums[i]==0){
i++;
}
}
return maxCount;
}