Skip to content

Instantly share code, notes, and snippets.

@haroldofurtado
Created February 15, 2018 07:48
Show Gist options
  • Save haroldofurtado/9ebe2e51c3080b0c8fe9bccddf852ae9 to your computer and use it in GitHub Desktop.
Save haroldofurtado/9ebe2e51c3080b0c8fe9bccddf852ae9 to your computer and use it in GitHub Desktop.
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