class Solution(object):
def isOneEditDistance(self, word1, word2):
l1=len(word1)
l2=len(word2)
if l1>l2:
return self.isOneEditDistance(word2,word1)
if l2-l1>1:
return False
i=0
while i<l1 and word1[i]==word2[i]:
i+=1
if l1==l2:
return word1[i+1:]==word2[i+1:]
else:
return word1[i:]==word2[i+1:]
网友评论