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 Mateusz_Tomkowiak
def longest_palindromic(text):
palindromes = []
for i in range(len(text)):
for j in range(i,len(text)+1):
tmp_text = text[i:j:]
if(tmp_text == tmp_text[::-1]):
palindromes.append(tmp_text);
longest_palindrome = ''
for palindrome in palindromes:
if len(palindrome)>len(longest_palindrome):
longest_palindrome = palindrome
print(longest_palindrome)
return longest_palindrome
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Oct. 23, 2016