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
nnnn
ort
IP Network & Broadcast Address Calculator 2
problem
prime number
QuickSort
HW5, SelectionSort FINNAL
add lambda
HW4
isPythagorasTriplet.py