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