straightforward java solution


  • 0
    F
        public int findMaxConsecutiveOnes(int[] nums) {
            int result = 0, startIdx = 0, endIdx = 0;
            for (; endIdx < nums.length; endIdx++) {
                if (nums[endIdx] == 0) {
                    result = Math.max(result, endIdx - startIdx);
                    startIdx = endIdx + 1;
                }
            }
            return Math.max(result, endIdx - startIdx);
        }
    

Log in to reply
 

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