My Java solution


  • 0
     public int findMaxConsecutiveOnes(int[] nums) {
            int max  = 0;
            int sum = 0;
            int mutiple = 1;
            
            for(int i = 0; i < nums.length; i++){
                sum += nums[i];
                mutiple *= nums[i];
                max = Math.max(max, sum);
                if(mutiple == 0){
                    sum = 0;
                    mutiple = 1;
                }
            }
            return max;
        }
    

Log in to reply
 

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