Created
June 25, 2020 14:35
-
-
Save nekomeowww/4ba662c773fbf016d9b323ecc5268091 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} word1 | |
* @param {string} word2 | |
* @return {number} | |
*/ | |
let minDistance = function(word1, word2) { | |
let wordArr1 = word1.split("") | |
let wordArr2 = word2.split("") | |
let count = 0 | |
for (let i = 0; i < wordArr1.length; i++) { | |
if (wordArr2[i] === undefined) { | |
wordArr1.slice(0, wordArr2.length + 1) | |
count++ | |
} | |
else if (wordArr2[i] !== wordArr1[i]) { | |
wordArr1[i] = wordArr2[i] | |
count++ | |
} | |
} | |
return count | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment