Very fast python solution. Beats 96%

  • 0

    If there is one distinct character, check if the rest of string matches.

            if s == t or abs(len(s) - len(t)) > 1: return False
            for i in range(min(len(s), len(t))):
                if s[i] != t[i]:
                    return s[:i]+s[i+1:] == t[:i]+t[i+1:] or s[:i]+s[i+1:] == t or t[:i]+t[i+1:] == s
            return True

Log in to reply

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