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>
This commit is contained in:
devarshitrivedi01 2022-11-15 00:17:23 +05:30 committed by GitHub
parent 00500d6108
commit 55b2045b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -16,6 +16,7 @@
| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | [C](./src/11.c) | Medium |
| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman) | [C](./src/12.c) | Medium |
| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [C](./src/13.c) | Easy |
| 14 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones/) | [C](./src/14.c) | Easy |
| 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [C](./src/20.c) | Easy |
| 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C](./src/21.c) | Easy |
| 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [C](./src/24.c) | Medium |

25
leetcode/src/14.c Normal file
View File

@ -0,0 +1,25 @@
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;
}