Created
February 15, 2018 07:48
-
-
Save haroldofurtado/9ebe2e51c3080b0c8fe9bccddf852ae9 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 isPalindrome(low, high) | |
while (low < high) do | |
if (low != high) | |
return false; | |
end | |
low += 1 | |
high -= 1 | |
end | |
return true; | |
end | |
def IsAlmostPalindrome(str) | |
low = 0 | |
high = str.size - 1 | |
while (low < high) do | |
if (str[low] == str[high]) | |
low += 1 | |
high -= 1 | |
else | |
if (isPalindrome(str[0].to_i + low + 1, str[0].to_i + high)) | |
return low | |
end | |
if (isPalindrome(str[0].to_i + low, str[0].to_i + high - 1)) | |
return high; | |
end | |
return -1 | |
end | |
end | |
return -2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment