LC: One Edit Distance - spiralgo/algorithms GitHub Wiki
The Essence:
When string t is longer than or of equal with s, then "one edit distance" can occur in 2 ways:
- A character is removed from
t. - A character is substituted/replaced.
Then simply checking for either of these conditions is enough for this problem.
Details:
The third condition of "edit distance", adding a character, is not needed to be checked. This can be achieved by calling the function again with reversed inputs.
A detailed explanation as well as the code can be found here: https://github.com/spiralgo/algorithms/pull/334