Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
long-repeat.First solution in Clear category for Long Repeat by poa
def long_repeat(line: str) -> int:
"""
length the longest substring that consists of the same char
"""
l = 0
max_l = 0
cur_char = line[:1]
for c in line:
if c == cur_char:
l += 1
else:
cur_char = c
l = 1
if l > max_l:
max_l = l
return max_l
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!")
March 12, 2024