28. Edit Distance
HardAlgorithms~40 min
Return the minimum number of single-character operations needed to turn word1 into word2.
The allowed operations are inserting a character, deleting a character, and replacing a character.
Examples
Example 1
- Input:
- word1 = "horse", word2 = "ros"
- Output:
- 3
- Why:
- horse -> rorse (replace h) -> rose (delete r) -> ros (delete e).
Example 2
- Input:
- word1 = "intention", word2 = "execution"
- Output:
- 5
Constraints
0 <= word1.length, word2.length <= 100Both words contain lowercase letters only.