213. Maximum Consecutive Ones
Given a binary array nums, return the maximum number of consecutive 1s in the array.
A binary array is an array that contains only 0s and 1s.
Example 1:
Input: nums = [1, 1, 0, 0, 1, 1, 1, 0]
Output: 3
Explanation:
The maximum consecutive 1s are present from index 4 to index 6, amounting to 3 1s
Example 2:
Input: nums = [0, 0, 0, 0, 0, 0, 0, 0]
Output: 0
Explanation:
No 1s are present in nums, thus we return 0
Now Your Turn!
Pick the correct output for the given inputInput: nums = [1, 0, 1, 1, 1, 0, 1, 1, 1]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 105
- nums[i] is either 0 or 1.