标签:
class Solution { public: int minDistance(string word1, string word2) { int s1=word1.length()+1; int s2=word2.length()+1; int len[s1][s2]; int i=0; int j=0; len[0][0] = 0; for(j=1;j<s2;j++) len[0][j]=j; for(j=1;j<s1;j++) len[j][0]=j; for(i=0;i<s1-1;i++) for(j=0;j<s2-1;j++){ if(word1[i] == word2[j]) len[i+1][j+1] = len[i][j]; else len[i+1][j+1] = min(len[i][j+1],len[i+1][j]) + 1; if(len[i+1][j+1] > len[i][j]+1) len[i+1][j+1]= len[i][j]+1; } return len[s1-1][s2-1]; } };
标签:
原文地址:http://www.cnblogs.com/julie-yang/p/4694521.html