leetcode 485 Max Consecutive Ones

Given a binary array, find the maximum number of consecutive 1s in this array.
Example 1:
1 | Input: [1,1,0,1,1,1] |
Note:
- The input array will only contain
0
and1
. - The length of input array is a positive integer and will not exceed 10,000
The basic idea is to set an tag recording the maxium ones at present.
when current number is One, current++
when current number is Zero, copy the max one to max
In case a situation where all the numbers are One, e.g. [1, 1, 1]
current == 3 , however, there is no Zero, so max still should be 0,
you should return the max of current
and max
1 | class Solution { |