Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
slices solution in Clear category for The Longest Palindromic by Olpag
def longest_palindromic(text):
palindromes = []
for i in range(len(text)):
for j in range(0, i):
substr = text[j:i + 1]
if substr == substr[::-1]:
palindromes.append(substr)
return max(palindromes, key=len) if palindromes else text[0]
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Jan. 23, 2019