Simple Java Solution


  • 0
    N
    public int findMaxConsecutiveOnes(int[] nums) {
            int count = 0;
            int finalCount = 0;
            for(int num : nums) {
                if(num == 1) {
                    count++;
                } else {
                    if(finalCount < count) {
                        finalCount = count;
                    }
                    count = 0;
                }
            }
            if(finalCount < count) { 
                finalCount = count;
            }
            return finalCount;
        }
    
    

Log in to reply
 

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