7.Edit|7.Edit Distance
【7.Edit|7.Edit Distance】https://leetcode.com/problems/edit-distance/
class Solution {
public:
int minDistance(string word1, string word2) {
int m = word1.length();
int n = word2.length();
vector> f(m + 1, vector(n + 1, 0));
for (int i = 0;
i <= m;
i++) {
f[i][0] = i;
}for (int j = 0;
j <= n;
j++) {
f[0][j] = j;
}for (int i = 1;
i <= m;
i++) {
for (int j = 1;
j <= n;
j++) {
if (word1[i-1] == word2[j-1]) {
f[i][j] = f[i-1][j-1];
} else {
f[i][j] = min(f[i-1][j-1], min(f[i-1][j], f[i][j-1])) + 1;
}
}
}return f[m][n];
}
};
推荐阅读
- 宽容谁
- 我要做大厨
- 增长黑客的海盗法则
- 画画吗()
- 2019-02-13——今天谈梦想()
- 远去的风筝
- 三十年后的广场舞大爷
- 叙述作文
- 20190302|20190302 复盘翻盘
- 学无止境,人生还很长