Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
"Long Repeat" solution in Clear category for Long Repeat by MrAnderson
def long_repeat(data):
"""
length the longest substring that consists of the same char
"""
from itertools import groupby
data_chunks = [''.join(chunk) for i, chunk in groupby(data)]
max_val = 0
for i in data_chunks:
if len(i) > max_val:
max_val = len(i)
return max_val
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert long_repeat('sdsffffse') == 4, "First"
assert long_repeat('ddvvrwwwrggg') == 3, "Second"
assert long_repeat('abababaab') == 2, "Third"
assert long_repeat('') == 0, "Empty"
print('"Run" is good. How is "Check"?')
Nov. 25, 2018