应该是可以的
因为只用考虑最多只有一个字符不同的情况
def match(s1, s2):
l1 = len(s1)
l2 = len(s2)
if abs(l1 - l2) > 1:
return False
if l2 < l1:
s1, s2 = s2, s1
l1, l2 = l2, l1
# replace
if l1 == l2:
count = 0
for c1, c2 in zip(s1, s2):
if c1 != c2:
count += 1
return count <= 1
# insert
else:
i = j = 0
while i < l1 and s1[i] == s2[j]:
i += 1
j += 1
j += 1
while i < l1 and s1[i] == s2[j]:
i += 1
j += 1
return i == l1