def findMaxConsecutiveOnes(self, nums):
n = 0
maxn = 0
for i,v in enumerate(nums):
if v == 1:
n += 1
else:
maxn = max(maxn, n)
n = 0
maxn = max(maxn, n)
return maxn
A Python Solution

counting 1's between any two 0's
class Solution(object): def findMaxConsecutiveOnes(self, nums): start = 0 res = 0 # deal with start/end case where 1's between any two 0's nums = [0] + nums + [0] for i, num in enumerate(nums): if num == 0: res = max(res, i  start  1) start = i return res