Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
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
Please
log in
to post a comment.
oppo mobile
9th jan1
me
homework1
Reading XML File
DISPLAY
RNG
inerse_matrix_gauss_jordan
Factorial
max area rectangle
stackse - search stackoverflow differently
Please log in to post a comment.