(1)动态规划
class Solution {
public:
int minDistance(string w1, string w2) {
int m=w1.length(),n=w2.length();
vector<vector<int>> v(m+1,vector<int>(n+1,0));
for(int i=0;i<m+1;i++) {
for(int j=0;j<n+1;j++) {
if(i==0 && j==0) v[i][j]=0;
else if(i==0 && j>0) v[i][j]=j;
else if(i>0 && j==0) v[i][j]=i;
else if(w1[i-1]==w2[j-1]) v[i][j]=v[i-1][j-1];
else v[i][j]=min(v[i-1][j],min(v[i][j-1],v[i-1][j-1]))+1;
}
}
return v[m][n];
}
};