Last active
June 11, 2019 03:55
-
-
Save DixieKorley/32df12e71bba94dbfdda6164a37a7d00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Max Consecutive Ones II""" | |
def max_consecutive_ones_II(bits): | |
res = max_count = 0 | |
counter = Counter() | |
for i in range(len(bits)): | |
counter[bits[i]] += 1 | |
maxf = max(maxf, counter[bits[i]]) | |
if res - maxf < 1: | |
res += 1 | |
else: | |
counter[bits[i - res]] -= 1 | |
return res | |
"""Max Consecutive Ones III""" | |
from collections import Counter | |
def max_consecutive_ones_III(bits, k): | |
maxf = res = 0 | |
counter = Counter() | |
for i in range(len(bits)): | |
counter[bits[i]] += 1 | |
maxf = max(maxf, counter[bits[i]]) | |
if res - maxf < k: | |
res += 1 | |
else: | |
counter[bits[i - res]] -= 1 | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment