We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a466f82 commit 87068c6Copy full SHA for 87068c6
my-submissions/m487.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
3
+ ones = [0]
4
+ consec_ones = 0
5
+
6
+ for num in nums :
7
+ if num == 0 :
8
+ if consec_ones :
9
+ ones.append(consec_ones)
10
+ ones.append((consec_ones := 0))
11
+ else :
12
+ consec_ones += 1
13
14
15
+ return max([sum(ones[x - 1:x+2]) + abs(min(ones[x], 1) - 1)
16
+ for x in range(1, len(ones) - 1)] + ones)
0 commit comments