Question:abcdef 和 qcfbcc 返回值为bc语言不限
算法如下:
public static string Compare(string str1, string str2)
{
if (str1.Length < str2.Length)
{
string strTemp = str1;
str1 = str2;
str2 = strTemp;
}
int[] sign = new int[str1.Length];
int length = 0;
int end = 0;
for (int i = 0; i < str2.Length; i++)
{
for (int j = str1.Length - 1; j >= 0; j-- )
{
if (str2[i] == str1[j])
{
if (i == 0 || j == 0)
sign[j] = 1;
else
sign[j] = sign[j - 1] + 1;
}
else
sign[j] = 0;
if (sign[j] > length)
{
length = sign[j];
end = j;
}
}
}
return str1.Substring(end - length + 1, length);