Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
three lines so far solution in Clear category for Long Repeat by Max0526
def long_repeat(line: str) -> int:
max_count, count = 1, 1
for i in range(1, len(line)): count = count + 1 if line[i] == line[i - 1] else 1; max_count = max(max_count, count)
return max_count if line else 0
'''
A rewrite of
def long_repeat(line: str) -> int:
if len(line) <= 1:
return len(line)
prev = line[0:1]
c = 1
ma = 0
for i in range(1,len(line)):
if line[i] == prev:
c += 1
if c > ma:
ma = c
if line[i] != prev:
prev = line[i:i+1]
c = 1
return ma
'''
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!")
May 3, 2023