Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Long Repeat by Vojtas
def long_repeat(line):
"""
length the longest substring that consists of the same char
"""
if len(line)==0:
return 0
litera = line[0]
dl = 1
wynik = {line[0]: 1}
for i in range(1, len(line), 1):
if line[i] == litera:
dl += 1
wynik[line[i]] = dl
else:
litera = line[i]
dl = 1
key_max = max(wynik.keys(), key=(lambda k: wynik[k]))
return wynik[key_max]
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. 17, 2018
Comments: