Description:

https://leetcode.com/problems/max-consecutive-ones/description/

Code:

 

Time & Space:
O(n) & O(1)

1 comments

Refactored:

class Solution {
public:
int findMaxConsecutiveOnes(vector& nums) {
int ans = 0, cur = 0;
for (const auto x : nums) {
if (x == 1) {
if (++cur > ans) ans = cur;
} else {
cur = 0;
}
}
return ans;
}
};

Leave a Reply

*