Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
In detail explained, but you have to figure out something on your own... solution in Clear category for Long Repeat by Rubenn
def long_repeat(line: str) -> int:
biggest = 0 # Length of the biggest substring:
current = 0 # Length of the intermediate substring:
# If the length of string is 0, then the answer is 0,
# And if there is only ane unique value we return the len of line:
if len(set(line)) == 1 or len(set(line)) == 0:
return len(line)
for i in range(1, len(line)):
#print(current)
if line[i-1] == line[i]: # Checking if the previous and current elements are the same:
current += 1 # And if yes increasing the len of the intermediate substrings len:
# print(current)
else: # If the condition is not satisfied,
if current >= biggest: # Checking if the current length of the substring is bigger
# than the len of the biggest value for the len of substring:
biggest = current # Giving the value of current to biggest if satisfied
current = 0 # Giving the current 0, to start things over:
return biggest + 1 # And this part I want you to think on your own :)
"""
length the longest substring that consists of the same char
"""
# your code here
return 0
print("Example:")
print(long_repeat("aa"))
assert long_repeat("sdsffffse") == 4
assert long_repeat("ddvvrwwwrggg") == 3
print("The mission is done! Click 'Check Solution' to earn rewards!")
July 8, 2023