Loading problem…
Given a binary array nums, return the maximum number of consecutive 1's in the array.
Example 1
Input: nums = [1,1,0,1,1,1]
Output: 3
Explanation: The array has a run of two 1s at the start and a run of three 1s at the end. The longest run is 3.
Example 2
Input: nums = [1,0,1,1,0,1]
Output: 2
Explanation: The runs of 1s have lengths 1, 2 and 1, so the longest is 2.
Example 3
Input: nums = [0,0,0]
Output: 0
Explanation: There are no 1s at all, so the answer is 0.
Sweep once, growing a run of consecutive 1's and resetting it to 0 on every 0; track the largest run seen.
Run checks all cases above. Submit evaluates all test cases.