Python O(n) solution


  • 0
    E
        def findMaxConsecutiveOnes(self, nums):
        	tot=0
        	var=0
        	for x in range(0,len(nums)):
        		if nums[x] ==1:
        			var+=1
        		else:
        			if var>tot:
        				tot=var
        			var=0
        	return max(tot,var)
    

Log in to reply
 

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