Consecutive Ones
You are given a list of integers nums which contains at least one 1. Return whether all the 1s appear consecutively.
Constraints
1 ≤ n ≤ 100,000wherenis the length ofnums
https://binarysearch.com/problems/Consecutive-Ones
Examples
Example 1
Input
- nums =
[0, 1, 1, 1, 2, 3]
Output
- answer =
True
Explanation
All the 1s appear consecutively here in the middle.
Example 2
Input
- nums =
[1, 1, 0, 1, 1]
Output
- answer =
False
Explanation
There’s two groups of consecutive 1s.
Leave a comment