Created
January 1, 2021 22:45
-
-
Save slapec/89bf23003168e4657e831db73606ee2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longest_palindrome(text): | |
text_length = len(text) | |
def find(longest_possible): | |
for window in range(text_length - longest_possible + 1): | |
subtext = text[window:window + longest_possible] | |
if subtext == subtext[::-1]: | |
return longest_possible | |
else: | |
return find(longest_possible - 1) | |
return find(text_length) | |
print(longest_palindrome('forgeeksskeegfor')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment