Simple Golang Solution in O(N)


  • 0
    B
    func findMaxConsecutiveOnes(nums []int) int {
    	max := 0
    	current := 0
    	for _, v := range nums {
    		if v == 1 {
    			current += 1
    		} else {
    			if current > max {
    				max = current
    			}
    			current = 0
    		}
    	}
    	if current > max {
    		max = current
    	}
    	return max
    }
    
    

Log in to reply
 

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