✨ Finishing 13 elements
This commit is contained in:
21
ScientificExpedition/double-substring.py
Normal file
21
ScientificExpedition/double-substring.py
Normal file
@@ -0,0 +1,21 @@
|
||||
def double_substring(line):
|
||||
"""
|
||||
length of the longest substring that non-overlapping repeats more than once.
|
||||
"""
|
||||
result = []
|
||||
for i in range(len(line) - 1):
|
||||
for j in range(i + 1, len(line) + 1):
|
||||
if line[i:j] in line[j:]:
|
||||
result.append(len(line[i:j]))
|
||||
|
||||
if len(result) > 0:
|
||||
return max(result)
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert double_substring('aaaa') == 2, "First"
|
||||
assert double_substring('abc') == 0, "Second"
|
||||
assert double_substring('aghtfghkofgh') == 3, "Third"
|
Reference in New Issue
Block a user