Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int ComputeDistance(string a, string b)
- {
- int length1 = a.Length;
- int length2 = b.Length;
- if (length1 == 0)
- return length2;
- if (length2 == 0)
- return length1;
- int[,] numArray = new int[length1 + 1, length2 + 1];
- for (int index1 = 1; index1 <= length1; ++index1)
- {
- for (int index2 = 1; index2 <= length2; ++index2)
- {
- int num = (int) b[index2 - 1] == (int) a[index1 - 1] ? 0 : 1;
- numArray[index1, index2] = Math.Min(Math.Min(numArray[index1 - 1, index2] + 1, numArray[index1, index2 - 1] + 1), numArray[index1 - 1, index2 - 1] + num);
- }
- }
- return numArray[length1, length2];
- }
- public static string TryGetClosestString(string input, List<string> options)
- {
- if (options.Count == 0)
- return "";
- int num1 = int.MaxValue;
- string option = options[0];
- for (int index = 0; index < options.Count; ++index)
- {
- int num2 = ComputeDistance(input, options[index]);
- if (num2 < num1)
- {
- option = options[index];
- num1 = num2;
- }
- }
- return option;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement