Created
June 13, 2019 00:01
-
-
Save dayvsonlima/197ca838e87abfaed63a4da6c4e8e593 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 isPalindrome(input): | |
length = len(input) | |
half = length / 2 | |
return input[0:(half)] == input[(length - half):length][::-1] | |
class Solution(object): | |
def longestPalindrome(self, input): | |
palindrome_size = len(input) | |
left = 0 | |
right = palindrome_size | |
while(palindrome_size > 1): | |
while(right <= len(input)): | |
if(isPalindrome(input[left:right])): | |
return input[left:right] | |
else: | |
left+=1 | |
right+=1 | |
palindrome_size-=1 | |
left = 0 | |
right = palindrome_size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment