Skip to content

Commit 1b2ccf2

Browse files
Refactor longest_ones method and improve formatting
1 parent 6d7bb8f commit 1b2ccf2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

data_structures/arrays/longest_ones_after_replacement.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
from typing import List
2-
3-
41
class LongestOnesAfterReplacement:
52
"""
63
Problem:
74
Given a binary array and an integer max_zero_flips, find the length of the
8-
longest subarray containing only 1s after flipping at most max_zero_flips zeros.
5+
longest subarray containing only 1s after flipping at most max_zero_flips
6+
zeros.
97
108
Example:
119
>>> solver = LongestOnesAfterReplacement()
1210
>>> solver.longest_ones([1, 0, 1, 1, 0, 1], 1)
1311
4
1412
"""
1513

16-
def longest_ones(self, nums: List[int], max_zero_flips: int) -> int:
14+
def longest_ones(self, nums: list[int], max_zero_flips: int) -> int:
1715
left = 0
1816
max_len = 0
1917
zeros_count = 0
@@ -34,4 +32,8 @@ def longest_ones(self, nums: List[int], max_zero_flips: int) -> int:
3432

3533
if __name__ == "__main__":
3634
solver = LongestOnesAfterReplacement()
37-
print("Longest Ones After Replacement:", solver.longest_ones([1, 0, 1, 1, 0, 1], 1))
35+
print(
36+
"Longest Ones After Replacement:",
37+
solver.longest_ones([1, 0, 1, 1, 0, 1], 1),
38+
)
39+

0 commit comments

Comments
 (0)