Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.
Input: "sea", "eat"
Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".
- The length of given words won't exceed 500.
- Characters in given words can only be lower-case letters.
m = len(word1)
n = len(word2)
dp = [[0 for _ in range(n+1)] for _ in range(m+1)]
for i in range(m+1):
for j in range(n+1):
if i == 0 and j == 0:
dp[i][j] = 0
if word1[i-1] == word2[j-1]
dp[i][j] = dp[i-1][j-1] + 1
dp[i][j] = max(dp[i-1][j],dp[i][j-1])
return m + n - 2*dp[m][n]