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 lukasz.bogaczynski
def longest_palindromic(phrase):
longest = ""
for i in range(0, len(phrase)):
for j in reversed(range(i + 1, len(phrase) + 1)):
if isPalindromic(phrase[i : j]) and len(phrase[i:j]) > len(longest):
longest = phrase[i:j]
return longest
def isPalindromic(phrase):
for index in range(0, len(phrase)):
if phrase[index] != phrase[len(phrase) - 1 - index]:
return False
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"
Nov. 13, 2017