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 karolk10
def longest_palindromic(text):
ans = ""
temp = ""
k = 0
for i in range(len(text)):
for j in range(len(text)-1,-1,-1):
if text[i] == text[j]:
for o in range(1,(j-i)//2+1):
if text[i+o] != text[j-o]:
k = 1
if k==0:
temp = text[i:j+1]
print(temp)
if len(temp)>len(ans):
ans = temp
k = 0
print(ans)
return ans
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Dec. 3, 2016