class Solution
{
public:
    bool isOneEditDistance(string s, string t)
    {
        int gap = s.size() - t.size();
        s = s + '0';
        t = t + '0';
        if (gap == 0)
        {
            int k = 0;
            for (int i = 0; i < s.size(); i++)
                if (s[i] != t[i])
                    k++;
            if (k == 1)
                return true;
        }
        else if (abs(gap) == 1)
        {
            for (int i = 0; i < s.size(); i++)
                if (s[i] != t[i] && s[i] != t[i + 1] && s[i + 1] != t[i])
                    return false;
            return true;
        }
        return false;
    }
};
