Leetcode 485 Solution
This article provides solution to leetcode question 485 (max-consecutive-ones)
Access this page by simply typing in "lcs 485" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/max-consecutive-ones
Solution
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int max_cnt = 0;
int cnt = 0;
nums.push_back(0);
for (auto num : nums)
if (num == 1)
cnt++;
else
{
max_cnt = max(max_cnt, cnt);
cnt = 0;
}
return max_cnt;
}
};