Golang solution


  • 0
    R
    func isOneEditDistance(s string, t string) bool {
        a := len(s)
        if a > len(t) {
            a = len(t)
        }
        for i:=0; i < a; i++ {
            if s[i] != t[i] {
                if len(s) == len(t) {
                    return s[i+1:] == t[i+1:]
                } else if len(s) < len(t) {
                    return s[i:] == t[i+1:]
                } else {
                    return t[i:] == s[i+1:]
                }
            }
        }
        
        k := len(s) - len(t)
        if k < 0 {
            k = k * -1
        }
        return k == 1
    }
      
    

Log in to reply
 

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