Skip to content

Instantly share code, notes, and snippets.

@renatoinline
Created January 19, 2016 02:25
Show Gist options
  • Select an option

  • Save renatoinline/1b919a50f11ad7ca238d to your computer and use it in GitHub Desktop.

Select an option

Save renatoinline/1b919a50f11ad7ca238d to your computer and use it in GitHub Desktop.
public static bool IsAlmostPalindrome(string word)
{
char[] normal = word.ToCharArray();
char[] reverse = word.ToCharArray();
Array.Reverse(reverse);
// Manualmente
//for (int i = normal.Length - 1, j = 0; i >= 0 ; i--, j++)
//{
// reverse[i] = normal[j];
//}
int erroCount = 0;
for (int i = 0; i < normal.Length; i++)
{
if (reverse[i] != normal[i])
erroCount += 1;
}
if(erroCount > 2)
return false;
return true;
}
@renatoinline

Copy link
Copy Markdown
Author

Checks whether a given string is palindrome. Also return true whether it is almost palindrome whith error rate at most one char.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment