Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Long Repeat by lukasz.bogaczynski
def long_repeat(text):
if len(text) < 1:
return 0
temp_substring = [text[0], 1]
largest_occurrence_count = 1
for character in text[1:]:
if character == temp_substring[0]:
temp_substring[1] = temp_substring[1] + 1
else:
if temp_substring[1] > largest_occurrence_count:
largest_occurrence_count = temp_substring[1]
temp_substring[0] = character
temp_substring[1] = 1
if temp_substring[1] > largest_occurrence_count:
largest_occurrence_count = temp_substring[1]
return largest_occurrence_count
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"?')
Oct. 19, 2017
Comments: