Description
Given a binary array nums containing only 0s and 1s, return the maximum number of consecutive 1s in the array. Solve in a single pass through the array.
Examples
Input:
nums = [1,1,0,1,1,1]Output:
3Explanation:
Three consecutive 1s.
Input:
nums = [1,1,1,1,1]Output:
5Explanation:
The entire array consists of consecutive 1s, so the maximum count is the length of the array (5).
Input:
nums = [0,0,1,0,0]Output:
1Explanation:
There is only one occurrence of 1 in the array, so the maximum consecutive count is 1.
Constraints
- •
1 ≤ nums.length ≤ 10⁵