Skip to content

Commit 853785c

Browse files
committed
Sync LeetCode submission Runtime - 5 ms (97.47%), Memory - 20.1 MB (40.04%)
1 parent f2c84f6 commit 853785c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1+
# Approach: One Pass
2+
3+
# Time: O(n)
4+
# Space: O(1)
5+
16
class Solution:
27
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
3-
return max(map(len, ''.join(map(str, nums)).split('0')))
8+
count = max_count = 0
9+
10+
for num in nums:
11+
if num == 1:
12+
count += 1
13+
else:
14+
max_count = max(max_count, count)
15+
count = 0
16+
17+
return max(max_count, count)
418

0 commit comments

Comments
 (0)