max consecutive ones

Max Consecutive Ones

Given a binary array, find the maximum number of consecutive 1s in this array.

example:

1
2
3
4
Input: [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s.
The maximum number of consecutive 1s is 3.

1
2
3
4
5
6
7
8
9
10
11
12
s = [1,1,0,1,1,1,0,1,1,1,1,0,1]
s.append(0)
print(s)
n=m=0
for i in range(0,len(s)):
if s[i] == 1:
n+=1
else:
if n > m:
m=n
n=0
print(m)