4-line C++ Clean and Concise


  • 0
    F
    bool isOneEditDistance(string s, string t) {
        for (int i = 0; i < s.size() && i < t.size(); ++i)
            if (s[i] != t[i])
                return s.substr(i + 1) == t.substr(i + 1) || s.substr(i) == t.substr(i + 1) || s.substr(i + 1) == t.substr(i);
        return abs<int>(s.size() - t.size()) == 1;
    }

Log in to reply
 

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