Skip to content

Instantly share code, notes, and snippets.

@xuefeng-huang
Created April 18, 2016 10:29
Show Gist options
  • Save xuefeng-huang/8d255586e72f2e8bf47ecdc96cd8b402 to your computer and use it in GitHub Desktop.
Save xuefeng-huang/8d255586e72f2e8bf47ecdc96cd8b402 to your computer and use it in GitHub Desktop.
def longest_palindrome(s):
for i in range(len(s), 0, -1):
for j in range(len(s)-i+1):
sub = s[j:j+i]
if sub == sub[::-1]:
return i
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment