Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
For each char if this one is the same of the current add 1 to count, using max each char tested solution in Clear category for Long Repeat by mathieu.roesch
def long_repeat(line):
"""
length the longest substring that consists of the same char
"""
maximum = count = 0
current = ''
for c in line:
if c == current:
count += 1
else:
count = 1
current = c
maximum = max(count,maximum)
return maximum
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
print(long_repeat('sdsffffse'))# == 4, "First"
print(long_repeat('ddvvrwwwrggg'))# == 3, "Second"
print(long_repeat('abababaab'))# == 2, "Third"
print(long_repeat(''))# == 0, "Empty"
print('"Run" is good. How is "Check"?')
July 18, 2018
Comments: