Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Iterate through all possible lengths solution in Clear category for Double Substring by martin.pilka
def double_substring(line):
# Iterate through all possible lengths staring from a longest one
for length in range(int(len(line)/2), 0, -1):
# Iterate through all possible starting positions of 1st substring (of a double-substring of this length)
for i in range(len(line)-length):
# Try to find 2nd substring
if line.find(line[i:i+length], i+length) >= 0:
# 2nd substring found, any other matches will be same length of shorter, so return its length now
return length
# No 2nd substring ever found, so return 0 length
return 0
Feb. 4, 2019
Comments: