class Solution { public: int minDistance(string word1, string word2) { int m=word1.size(); int n=word2.size(); if(m==0)return n; if(n==0)return m; int v[501][501]; int i,j; for(i=0;i<=m;i++) { v[i][0]=i; } for(j=0;j<=n;j++) { v[0][j]=j; } for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { if(word1[i-1]==word2[j-1]) v[i][j]=v[i-1][j-1]; else v[i][j]=min(v[i][j-1],min(v[i-1][j],v[i-1][j-1]))+1; } } return v[m][n]; } };