Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Counter "streak" solution in Clear category for Long Repeat by mithilkotak
def long_repeat(line: str) -> int:
"""
length the longest substring that consists of the same char
"""
# your code here
streak=1
maxstreak=0
if line:
for i in range(len(line)-1):
if line[i]==line[i+1]:
streak+=1
else:
if streak>maxstreak:
maxstreak=streak
streak=1
if streak>maxstreak: #Longest repeat might be at end of line
maxstreak=streak
return maxstreak
print("Example:")
print(long_repeat("sdsffffse"))
assert long_repeat("sdsffffse") == 4
assert long_repeat("ddvvrwwwrggg") == 3
print("The mission is done! Click 'Check Solution' to earn rewards!")
Oct. 1, 2022
Comments: