如下内容段是关于C#通过编辑距离算法实现字符串相似度比较的内容,希望能对各位有所帮助。
public class LevenshteinDistance
{
private static LevenshteinDistance _instance=null;
public static LevenshteinDistance Instance
{
get
{
if (_instance == null)
{
return new LevenshteinDistance();
}
return _instance;
}
}
public int LowerOfThree(int first, int second, int third)
{
int min = first;
if (second < min)
min = second;
if (third < min)
min = third;
return min;
}
public int Levenshtein_Distance(string str1, string str2)
{
int[,] Matrix;
int n=str1.Length;
int m=str2.Length;
int temp = 0;
char ch1;
char ch2;
int i = 0;
int j = 0;
if (n ==0)
{
return m;
}