Java Solution. As easy as it gets


  • 0
    E
    public int findMaxConsecutiveOnes(int[] nums) {
            int currentMax = 0, count = 0;
            for(int i : nums){
               count = i == 1 ? count + 1 : 0;
               currentMax = count > currentMax ? count : currentMax;
            }
           return currentMax; 
         }
    }

Log in to reply
 

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