Guest User

Untitled

a guest
Feb 26th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. def get_longest_palindrome(text):
  2. best_palindrome = ''
  3. length = len(text)
  4. for i in range(length * 2 - 1):
  5. start = i / 2 - i % 2
  6. end = i / 2 + 1
  7. while start > 0 and end < length and text[start] == text[end]:
  8. start -= 1
  9. end += 1
  10. candidate = text[start+1:end]
  11. if len(candidate) > len(best_palindrome):
  12. best_palindrome = candidate
  13. return best_palindrome
Add Comment
Please, Sign In to add comment