Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straight O(N) solution in Clear category for Long Repeat by Lemmi
def long_repeat(line):
cur_ch = 'a'
cur_num = max_num = 0
for ch in line:
if ch == cur_ch:
cur_num += 1
else:
cur_ch = ch
cur_num = 1
if max_num < cur_num:
max_num = cur_num
return max_num
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"?')
Aug. 15, 2017
Comments: