Sharing my python solution, beats 100% so far


  • 0
    W
    class Solution(object):
        def isOneEditDistance(self, s, t):
            s,l = (s,t) if len(s) <= len(t) else (t,s)
            
            i = 0 
            for i in xrange(len(s)):
                if s[i] != l[i]:
                    return s[i+1:] == l[i+1:] or s[i:] == l[i+1:]
            return len(l)-len(s) == 1
    

Log in to reply
 

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