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 cs1g
def IsPalindrome(s):
return s == s[::-1]
def longest_palindromic(text):
for length in range(len(text), 0, -1):
for start in range(len(text) - length + 1):
if IsPalindrome(text[start:(length + start)]):
return text[start:(length + start)]
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
May 30, 2017