Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Click here to see the full article post

There an error for the one pass solution minDistance = Math.min(minDistance, Math.abs(i1 - i1)); have to be minDistance = Math.min(minDistance, Math.abs(i1 - i2));

Thanks! I have corrected it.

You do not need currentDistance here.

Check words[i] is word1 or word2, else continue. This can save a little.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.