Skip to content

Instantly share code, notes, and snippets.

@uhnomoli
Last active May 20, 2016 06:17
Show Gist options
  • Save uhnomoli/4d9ed716a321c7eae854b88bfc568940 to your computer and use it in GitHub Desktop.
Save uhnomoli/4d9ed716a321c7eae854b88bfc568940 to your computer and use it in GitHub Desktop.
def longest_substr(data):
supstr = data[0]
end = len(supstr)
substr = ''
for i in xrange(end):
start = i + 1 + len(substr)
if (start >= end + 1):
break
for j in xrange(start, end + 1):
if j - i > len(substr) and is_substr(supstr[i:j], data):
substr = supstr[i:j]
return substr
def is_substr(needle, haystack):
for bale in haystack:
if needle not in bale:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment