```
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);
}
```