diff --git a/leetcode/README.md b/leetcode/README.md index 216885c0..3fcec08e 100644 --- a/leetcode/README.md +++ b/leetcode/README.md @@ -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 | | 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 | +| 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 | | 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 | diff --git a/leetcode/src/485.c b/leetcode/src/485.c new file mode 100644 index 00000000..a2887615 --- /dev/null +++ b/leetcode/src/485.c @@ -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; +}