Delete Operation for Two Strings LeetCode solution in Python
1class Solution:2def minDistance(self, word1: str, word2: str) -> int:3m = len(word1)4n = len(word2)5a = []6for i in range(m + 1):7a.append([])8for j in range(n + 1):9a[-1].append(0)1011for i in range(m):12for j in range(n):13if word1[i] == word2[j]:14a[i + 1][j + 1] = 1 + a[i][j]15else:16a[i + 1][j + 1] = max(a[i][j + 1], a[i + 1][j])1718return m + n - (2 * a[-1][-1])