LeetCode 485. Max Consecutive Ones Posted on 2021-02-15 Edited on 2024-11-24 In LeetCode 123456789101112131415class Solution {public: int findMaxConsecutiveOnes(vector<int>& nums) { int cnt = 0, ans = 0; for (int num : nums) { if (num == 1) { ++cnt; } else { ans = max(ans, cnt); cnt = 0; } } return max(ans, cnt); }};