Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Long Repeat by bart.t
def long_repeat(line):
"""
length the longest substring that consists of the same char
"""
c = []
if len(line) == 1:
longest = 1
else:
for i in range(len(line)-1):
if line[i] != line[i+1]:
c.append(1)
elif i == 0:
c.append(1)
c[-1] += 1
else:
c[-1] += 1
i += 1
if len(c) == 1:
longest = c[0]
elif len(c) == 0:
longest = 0
else:
longest = max(c)
return longest
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"
print('"Run" is good. How is "Check"?')
Jan. 24, 2018