auto-generated entry for Max Consecutive Ones. the solution files are available below.
solution files
- C++
max-consecutive-ones/synced-solution.cpp - Python
max-consecutive-ones/synced-solution.py - TypeScript
max-consecutive-ones/synced-solution.ts
Collected C++, Python, TypeScript solutions for max consecutive ones. Add a dedicated write-up later if you want deeper notes.
auto-generated entry for Max Consecutive Ones. the solution files are available below.
max-consecutive-ones/synced-solution.cppmax-consecutive-ones/synced-solution.pymax-consecutive-ones/synced-solution.tsdef findMaxConsecutiveOnes(nums):
max_count = class="syntax-number">0
current_count = class="syntax-number">0
for num in nums:
if num == class="syntax-number">1:
current_count += class="syntax-number">1
max_count = max(max_count, current_count)
else:
current_count = class="syntax-number">0
return max_count
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int max_count = class="syntax-number">0, current_count = class="syntax-number">0;
for (int num : nums) {
if (num == class="syntax-number">1) {
current_count++;
max_count = max(max_count, current_count);
} else {
current_count = class="syntax-number">0;
}
}
return max_count;
}
};
function findMaxConsecutiveOnes(nums: number[]): number {
let maxCount = class="syntax-number">0, currentCount = class="syntax-number">0;
for (const num of nums) {
if (num === class="syntax-number">1) {
currentCount++;
maxCount = Math.max(maxCount, currentCount);
} else {
currentCount = class="syntax-number">0;
}
}
return maxCount;
}