Easy Understand Java Solution use One Point


  • 0
    W
        public int findMaxConsecutiveOnes(int[] nums) {
            int maxSum = 0;
            int index_0 = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] == 0) {
                    index_0 = i + 1;
                }
                maxSum = Math.max(i + 1 - index_0, maxSum);
            }
            return maxSum;
        }
    
    

Log in to reply
 

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