5 line clear C solution


  • 0
    W
    bool isOneEditDistance(string s, string t) {
            int m = s.size(), n = t.size(), i = 0;
            while (i < m && i < n && s[i] == t[i]) i++;
            
            if (m == i) return n == i+1;
            if (n == i) return m == i+1;
            return s.substr(i+1) == t.substr(i) || s.substr(i+1) == t.substr(i+1) || s.substr(i) == t.substr(i+1);
        }
    

Log in to reply
 

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