我需要找到一个词和它的排序词(例如:apple和aelpp)之间的编辑距离,只使用递归的插入和删除。你知道吗
我发现了一些使用插入、删除和替换的源代码,但我不知道如何只使用插入和删除。你知道吗
这是我找到的代码:
def ld(s, t):
if not s: return len(t)
if not t: return len(s)
if s[0] == t[0]: return ld(s[1:], t[1:])
l1 = ld(s, t[1:])
l2 = ld(s[1:], t)
l3 = ld(s[1:], t[1:])
return 1 + min(l1, l2, l3)
需要进行哪些编辑才能只找到插入和删除的数量?你知道吗
删除
l3
,它会像这样计算替换可以看到
ld('apple', 'applx')
等于1,而具有相同参数的ld2
的计算结果为2。你知道吗相关问题 更多 >
编程相关推荐