mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
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:
parent
00500d6108
commit
55b2045b19
@ -16,6 +16,7 @@
|
|||||||
| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | [C](./src/11.c) | Medium |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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
25
leetcode/src/14.c
Normal 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;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user