Created
January 19, 2016 02:25
-
-
Save renatoinline/1b919a50f11ad7ca238d 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
| 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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checks whether a given string is palindrome. Also return true whether it is almost palindrome whith error rate at most one char.