美文网首页
161. One Edit Distance

161. One Edit Distance

作者: 阿团相信梦想都能实现 | 来源:发表于2016-12-10 07:01 被阅读0次
    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:]
    

    相关文章

      网友评论

          本文标题:161. One Edit Distance

          本文链接:https://www.haomeiwen.com/subject/svbymttx.html