JuniorArray

Max Consecutive Ones

Given a binary array nums, return the maximum number of consecutive 1's in the array.

Example 1
Inputnums = [1,1,0,1,1,1]
Output3
The first two digits or the last three digits are consecutive 1s, and the maximum number of consecutive 1s is 3.
Example 2
Inputnums = [1,0,1,1,0,1]
Output2
The longest run of consecutive 1s has length 2.

Constraints

  • 1 <= nums.length <= 10^5
  • nums[i] is either 0 or 1.

Asked at 13 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate