Skip to content

Commit 87068c6

Browse files
committed
weekly_prem
1 parent a466f82 commit 87068c6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

my-submissions/m487.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
ones.append(consec_ones)
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

Comments
 (0)