Edit Distance
Problem statement
Given two strings word1 and word2, return the minimum number of operations needed to transform word1 into word2.
One operation may insert one character, delete one character, or replace one character.
Function
minDistance(word1: String, word2: String) → intExamples
Example 1
word1 = "horse"word2 = "ros"return = 3Replace h with r, delete the second r, and delete e.
Example 2
word1 = "intention"word2 = "execution"return = 5Five insert, delete, or replace operations are sufficient and optimal.
Example 3
word1 = ""word2 = "abc"return = 3Insert the three characters of the target.
Constraints
0 <= word1.length, word2.length <= 500.- Both strings contain only lowercase English letters.