classSolution:# @return an integerdefminDistance(self,word1,word2):len1=len(word1)len2=len(word2)dp=[[0forjinxrange(len2+1)]foriinxrange(len1+1)]foriinxrange(len1+1):dp[i][0]=iforjinxrange(len2+1):dp[0][j]=jforiinxrange(1,len1+1):forjinxrange(1,len2+1):ifword1[i-1]==word2[j-1]:dp[i][j]=dp[i-1][j-1]else:dp[i][j]=min(dp[i-1][j-1],dp[i][j-1],dp[i-1][j])+1returndp[len1][len2]