LeetCode 72. Edit Distance
来源:互联网 发布:陈子豪淘宝外设店 编辑:程序博客网 时间:2024/06/06 19:34
描述
问一个字符串需要多少的操作才能变成另一个字符串
解决
动态规划
class Solution {public: int minDistance(string word1, string word2) { int length1 = word1.size(); int length2 = word2.size(); vector<vector<int>> dp(length1 + 1, vector<int>(length2 + 1, 0)); for (int i = 0; i <= length1; ++i) dp[i][0] = i; for (int j = 0; j <= length2; ++j) dp[0][j] = j; for (int i = 0; i < length1; ++i) { for (int j = 0; j < length2; ++j) { int cost = word1[i] == word2[j] ? 0 : 1; dp[i + 1][j + 1] = min(min(dp[i][j + 1] + 1, dp[i + 1][j] + 1), dp[i][j] + cost); } } return dp[length1][length2]; }};
0 0
- LeetCode 72. Edit Distance
- [LeetCode]72.Edit Distance
- LeetCode --- 72. Edit Distance
- [Leetcode] 72. Edit Distance
- [leetcode] 72.Edit Distance
- [leetcode] 72.Edit Distance
- Leetcode 72. Edit Distance
- LeetCode 72. Edit Distance
- leetcode 72. Edit Distance
- LeetCode 72. Edit Distance
- Leetcode 72. Edit Distance
- Leetcode:72. Edit Distance
- 【LeetCode】72. Edit Distance
- leetCode 72. Edit Distance
- [leetcode] 72. Edit Distance
- [LeetCode] 72. Edit Distance
- leetcode 72. Edit Distance
- leetcode 72. Edit Distance
- 51nod算法马拉松20 C、战忽局的手段
- 分享STM32F429开发板例程资料集,网盘哦
- 使用异步Servlet改进应用性能
- java 代码块
- 在tableView中添加webView显示商品图文详情 自适应高度
- LeetCode 72. Edit Distance
- 不是人人都懂的学习要点
- Android 系统架构
- hadoop2.2.0单机伪分布,运行Wordcount时候出错
- ActionContext和ServletActionContext
- 投标保证金归属于业主还是属于监管业主的财政部门?
- wlys
- 技术博文分类网址记录
- NN远程桌面SDK之Delphi开发源码