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 FUbaer
def long_repeat(line: str) -> int:
count = 1 # substring counter - minimum length is one
result = 1 # result - substring minimum length is one
x = 0 # need for the while loop
if (len(line)) == 0: # if string is empty
return False # return False
while x < (len(line)-1): # we loop to the penultimate element
if (line[x]) == (line[x+1]):# if two successive characters are equal
count += 1 # we count the substring up
else:
count = 1 # reset the substring counter to 1
if count > result: # if the substring counter is greater than the maximumm
result = count
x += 1 # loop forward
return result # return the maximim substring
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"?')
Feb. 5, 2020
Comments: