JavaScript solution


  • 0
    G
    /**
     * @param {number[]} nums
     * @return {number}
     */
    var findMaxConsecutiveOnes = function(nums) {
        let max = 0;
        let currentCount = 0;
        
        nums.forEach(num => {
            if (num === 1) {
                currentCount++;
                
                if (currentCount > max)
                    max = currentCount;
                    
                return;
            }
            
            currentCount = 0;
        });
        
        return max;
    };
    

Log in to reply
 

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