0072. Edit Distance
Hard | String + DP | 88 ms (98.31%), 16.6 MB (84.05%)
Last updated
Was this helpful?
Hard | String + DP | 88 ms (98.31%), 16.6 MB (84.05%)
Last updated
Was this helpful?
Source: GitHub:
Given two strings word1
and word2
, return the minimum number of operations required to convert word1
to word2
.
You have the following three operations permitted on a word:
Insert a character
Delete a character
Replace a character
We create a 2D array and initialize values on table[i][0]
and table[0][j]
Then iterate through each char by the nested for loops to find the minimum operations.
i in range(1, len(word1) + 1)
j in range(1, len(word2) + 1)