Slow Python


  • 0
    class Solution(object):
        def isOneEditDistance(self, s, t):
            lens, lent = len(s), len(t)
            if abs(lens - lent) >= 2:
                return False
            s, t = s if lens < lent else t, t if lens < lent else s
            if lens == lent:
                if s == t:
                    return False
                for i in xrange(lens):
                    if s[:i] + s[i+1:] == t[:i] + t[i+1:]:
                        return True
                return False
            else:
                for j in xrange(len(t)):
                    if t[:j] + t[j+1:] == s:
                        return True
                return False
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.