题目:
题解:
static inline int Min(const int a, const int b, const int c) {
int min = (a < b) ? a : b;
return (min < c) ? min : c;
}
int minDistance(char * word1, char * word2){
int m = strlen(word1), n = strlen(word2);
int dp[m + 1][n + 1];
for (int i = 0; i < m + 1; i++) {
dp[i][0] = i;
}
for (int j = 1; j < n + 1; j++) {
dp[0][j] = j;
}
for (int i = 1; i < m + 1; i++) {
for (int j = 1; j < n + 1; j++) {
if (word1[i - 1] == word2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1];
} else {
dp[i][j] = 1 + Min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
}
}
}
return dp[m][n];
}