Java O(n) Solution Runtime: 7 ms


  • 0
    W
    class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int maxCount = 0;
            int count = 0;
            for (int i : nums) {
                if (i == 1) {
                    count++;
                } else {
                    maxCount = Math.max(count, maxCount);
                    count = 0;
                }
            }
            return Math.max(count, maxCount);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.