My 4 line python


  • 3

    Find the first distinct char and judge the rest of them.

    class Solution(object):
        def isOneEditDistance(self, s, t):
            i = 0
            while  i < min(len(s), len(t)) and s[i] == t[i] :
                i += 1
            return not (i == len(s) == len(t)) and s[i + (len(s) >= len(t)):] == t[i + (len(s) <= len(t)):]

Log in to reply
 

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