Max Consecutive Ones – LeetCode 485
Problem
Description
Given a binary array, find the maximum number of consecutive 1s in this array.
Example
Input: [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.
Answer
Original
Code
1 | class Solution { |
思路
无话可说。时间复杂度$O(n)$,空间复杂度$O(1)$。
耗时$38$ ms,排名$23.29\%$
Better
思路
还没看到更好的思路。