Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.

In one step, you can delete exactly one character in either string.

&nbsp;
Example 1:

Input: word1 = "sea", word2 = "eat"
Output: 2
Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".


Example 2:

Input: word1 = "leetcode", word2 = "etco"
Output: 4


&nbsp;
Constraints:


	1 &lt;= word1.length, word2.length &lt;= 500
	word1 and word2 consist of only lowercase English letters.


class Solution:
    def minDistance(self, word1: str, word2: str) -> int:
        m = len(word1)
        n = len(word2)
        a = []
        for i in range(m+1):
            a.append([])
            for j in range(n+1):
                a[-1].append(0)
        
        for i in range(m):
            for j in range(n):
                if word1[i]==word2[j]:
                    a[i+1][j+1] = 1 + a[i][j]
                else:
                    a[i+1][j+1] = max( a[i][j+1], a[i+1][j])
					
        return m + n - ( 2 * a [-1][-1] )
class Solution {
    public int minDistance(String word1, String word2) {
        int n = word1.length();
        int m = word2.length();

        int[][]dp = new int[n+1][m+1];

        for(int i = 0; i<n; i++){
            dp[i][0] = 0;
        }

        for(int i = 0; i<m; i++){
            dp[0][i] = 0;
        }

        for(int i = 1; i<=n; i++){
            for(int j = 1; j<=m; j++){
                if(word1.charAt(i-1) == word2.charAt(j-1)){
                    dp[i][j] = 1+dp[i-1][j-1];
                }else{
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }

        int common = dp[n][m];
        return (n+m)-(2*common);

    }
}
class Solution {
public:
    int tabulation(string s1, string s2){
        vector<vector<int>> table(s1.length() + 1, vector<int>(s2.length() + 1));
        for(int i=1; i<s1.length()+1; i++){
            for(int j=1; j<s2.length()+1; j++){
                if(s1[i-1] == s2[j-1]){
                    table[i][j] = 1 + table[i-1][j-1];
                }
                else{
                    table[i][j] = max(table[i-1][j], table[i][j-1]);
                }
            }
        }
        return table[s1.length()][s2.length()];
    }
    
    int minDistance(string word1, string word2) {
        int lcs = tabulation(word1, word2);
        return (word1.length() - lcs) + (word2.length() - lcs);
    }
};
var minDistance = function(word1, word2) {
	const WORD1_LEN = word1.length;
	const WORD2_LEN = word2.length;
	const dp = Array(WORD1_LEN + 1).fill('').map(() => Array(WORD2_LEN + 1).fill(0));

	for (let index = 1; index <= WORD1_LEN; index++) {
		for (let j = 1; j <= WORD2_LEN; j++) {
			dp[index][j] = word1[index - 1] === word2[j - 1]
				? dp[index - 1][j - 1] + 1
				: Math.max(dp[index - 1][j], dp[index][j - 1]);
		}
	}

	return WORD1_LEN + WORD2_LEN - 2 * dp[WORD1_LEN][WORD2_LEN];
};
Delete Operation for Two Strings