相似度匹配算法实际是计算字符串之间的编辑距离。
经常刷算法的同学,就应该知道这个是一个可迭代可递归实现的中难度的leetcode算法。
详细思路可以在【思路分析指引】看看,我就直接给出对应的的代码!
二维dp算法
/**
* 相似du匹配算法,约靠近返回的值越高
* @param target
* @param findOb
* @return
*/
public static double matchStr(String target ,Object findOb ) {
//length
String find = String.valueOf(findOb);
int Length1 = target.length();
int Length2 = find.length();
int distance = 0;
if (Length1 == 0) {
distance = Length2;
}
if (Length2 == 0) {
distance = Length1;
}
if (Length1 != 0 && Length2 != 0) {
int[][] dp = new int[Length1 + 1][Length2 + 1];
//编号
int initValue = 0;
for (int i = 0; i <= Length1; i++) {
dp[i][0] = initValue;
initValue++;
}
initValu