Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Longest Palindromic by cinekk
def check(txt):
if txt == txt[::-1]:
return txt
return ''
def longest_palindromic(text):
if text == text[::-1]:
return text
result = ''
j, i, text_len, longest_ss = 0, 1, len(text), 0
while j < text_len:
while i < text_len:
tmp = check(text[j:i])
if len(tmp) > longest_ss:
longest_ss = len(tmp)
result = tmp
i += 1
j += 1
i = j + 1
return result
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Nov. 8, 2016