Edit Distance
Hard
LC #72
two strings2d dplevenshteinNot attempted yet
Return the minimum number of operations to turn word1
into word2. Each operation is one of:
- insert a character
- delete a character
- replace a character with another
Example 1
Input: word1 = "horse", word2 = "ros"
Output: 3
horse → rorse (replace h)
rorse → rose (delete r)
rose → ros (delete e)
Example 2
Input: word1 = "intention",
word2 = "execution"
Output: 5
Example 3
Input: word1 = "", word2 = "abc"
Output: 3
Constraints
- 0 ≤ len(word1), len(word2) ≤ 500
- lowercase letters only