Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple but easy to read solution in Clear category for Long Repeat by pavel.fasther
def long_repeat(line: str) -> int:
"""
length the longest substring that consists of the same char
"""
counter = 0
result = 0
last = ""
for letter in line:
if letter == last:
counter += 1
else:
result = counter if counter > result else result
counter = 1
last = letter
return counter if counter > result else result # if the longest substring was in last part, we need to send counter
Dec. 29, 2019