dp
with dimensions (len(word1) + 1) x (len(word2) + 1)
.dp
with indices 0
to len(word2)
, representing the operations needed to convert an empty word1
to word2
.dp
with indices 0
to len(word1)
, representing the operations needed to convert word1
to an empty word2
.word1
and word2
using two nested loops.(i, j)
, check if word1[i - 1]
is equal to word2[j - 1]
.dp[i][j]
to dp[i - 1][j - 1]
.dp[i][j]
to the minimum of dp[i - 1][j]
, dp[i][j - 1]
, and dp[i - 1][j - 1]
plus 1.dp[len(word1)][len(word2)]
is the minimum number of operations required.