LC: One Edit Distance - spiralgo/algorithms GitHub Wiki

One Edit Distance

The Essence:

When string t is longer than or of equal with s, then "one edit distance" can occur in 2 ways:

  1. A character is removed from t.
  2. 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