Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Longest Palindromic by Julita_Pogorzelska
def longest_palindromic(text):
cand=""
max=0
if diffchars(text):
cand=text[0]
else:
for i in range(len(text)):
for j in range (len(text)-1, 0, -1):
if text[i]==text[j]:
print(i,j)
if is_palindrome(text[i:j+1]):
if len(text[i:j+1])>max:
cand=text[i:j+1]
max=len(cand)
return cand
def is_palindrome(text):
if text == text[::-1]:
return True
return False
def diffchars(text):
seen=[]
for i in text:
if i in seen:
return False
seen.append(i)
return True
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. 29, 2017