mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
chore: add LeetCode problem 485 (#981)
* Create 485.c added "485. Max Consecutive Ones" solution * Update README.md Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
parent
a0f658311d
commit
25f3b63d5b
@ -72,6 +72,7 @@
|
|||||||
| 442 | [Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array/) | [C](./src/442.c) | Medium |
|
| 442 | [Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array/) | [C](./src/442.c) | Medium |
|
||||||
| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance/) | [C](./src/461.c) | Easy |
|
| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance/) | [C](./src/461.c) | Easy |
|
||||||
| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [C](./src/476.c) | Easy |
|
| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [C](./src/476.c) | Easy |
|
||||||
|
| 485 | [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones/) | [C](./src/485.c) | Easy |
|
||||||
| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) | [C](./src/509.c) | Easy |
|
| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) | [C](./src/509.c) | Easy |
|
||||||
| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital/) | [C](./src/520.c) | Easy |
|
| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital/) | [C](./src/520.c) | Easy |
|
||||||
| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i/) | [C](./src/561.c) | Easy |
|
| 561 | [Array Partition I](https://leetcode.com/problems/array-partition-i/) | [C](./src/561.c) | Easy |
|
||||||
|
23
leetcode/src/485.c
Normal file
23
leetcode/src/485.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
int max(a,b){
|
||||||
|
if(a>b)
|
||||||
|
return a;
|
||||||
|
else
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int findMaxConsecutiveOnes(int* nums, int numsSize){
|
||||||
|
int count = 0;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < numsSize; i++)
|
||||||
|
{
|
||||||
|
if (nums[i] == 0)
|
||||||
|
count = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
result = max(result, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user