Mid/Senior
One Edit Distance
Given two strings s and t, return true if they are exactly one edit distance apart; otherwise, return false.
One edit is defined as exactly one of the following operations performed on s:
- Insert one character.
- Delete one character.
- Replace one character with another character.
The strings must differ by exactly one edit, so two identical strings are not considered one edit distance apart.
Example 1
Input
s = "ab", t = "acb"Output
trueInserting the character
c into s produces t.Example 2
Input
s = "", t = ""Output
falseThe strings are identical, so they are zero edits apart, not one edit apart.
Constraints
- 0 <= s.length, t.length <= 10^4
- s and t consist of lowercase letters, uppercase letters, and digits