```
public boolean isOneEditDistance(String s, String t) {
int lens = s.length(), lent = t.length(), i = 0, j = 0;
for (; i < lens && i < lent && s.charAt(i) == t.charAt(i); i++);
for (; j < lens && j < lent && s.charAt(lens - 1 - j) == t.charAt(lent - 1 - j); j++);
return (lens == lent && i + j + 1 == lens) || (Math.abs(lens - lent) == 1 && i + j + 1 == Math.max(lens, lent));
}
```