int minDistance(char * word1, char * word2){
int len1=strlen(word1);
int len2=strlen(word2);
int dp[len1+1][len2+1];
for(int a=0;a<len2+1;a++){
dp[0][a]=0;
}
for(int a=0;a<len1+1;a++){
dp[a][0]=0;
}
for(int a=1;a<len1+1;a++){
for(int b=1;b<len2+1;b++){
if(word1[a-1]==word2[b-1]){
dp[a][b]=dp[a-1][b-1]+1;
}
else{
dp[a][b]=dp[a-1][b]>dp[a][b-1]?dp[a-1][b]:dp[a][b-1];
}
}
}
int Record=0;
if(len1>dp[len1][len2]){
Record=Record+len1-dp[len1][len2];
}
if(len2>dp[len1][len2]){
Record=Record+len2-dp[len1][len2];
}
return Record;
}
|