Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Get the longest repeated non-overlapping substring
def double_substring(string): length = len(string) limit = int(length / 2) for max_ in range(limit, 0, -1): overlaps = [] for i in range(0, 1+length-max_*2): offset = i + max_ part = string[i:offset] if part in overlaps: continue index = string.find(part, i + 1) while index > 0: if index < offset: overlaps.append(part) break offset = index + max_ index = string.find(part, index + 1) if index < 0: print(part) return max_ return 0 print(double_substring('aaaa')) print(double_substring('abcab')) print(double_substring('aghtfghkofgh')) print(double_substring('abc')) print(double_substring('abbaabbadabbaabba'))
run
|
edit
|
history
|
help
0
Achinta
abc1
EJ_2_python_20.068.214-9_20.116.927-5
codigo1
shuru4
Help me
Game2
test2.py
Faiha Lesson 3
queue and stack