Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Long Repeat (revised solution) solution in Clear category for Long Repeat by vlad.n
def long_repeat(line):
"""Finds the longest substring that consists of the same char.
"""
if not line:
return 0
max_length = 1
current_length = 1
for i in range(1, len(line)):
if line[i] == line[i - 1]:
current_length += 1
if current_length > max_length:
max_length = current_length
else:
current_length = 1
return max_length
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"
print('"Run" is good. How is "Check"?')
Nov. 27, 2017