Fast java solution


  • 0
    M
    public int findMaxConsecutiveOnes(int[] nums) {
        int max = 0;
        int a = -1, b = -1;
        for(int i = 0; i <= nums.length; i++) {
            if(i == nums.length || nums[i] == 0) {
                max = Math.max(max, i - a - 1);
                
                a = b;
                b = i;
            }
        }
        return max;
    }

Log in to reply
 

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