当前位置:网站首页>leetcode 72. Edit Distance 编辑距离(中等)
leetcode 72. Edit Distance 编辑距离(中等)
2022-07-04 21:43:00 【InfoQ】
一、题目大意
- 0 <= word1.length, word2.length <= 500
- word1 和 word2 由小写英文字母组成
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public int minDistance(String word1, String word2) {
int m = word1.length();
int n = word2.length();
int[][] dp = new int[m + 1][n + 1];
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0) {
dp[i][j] = j;
} else if (j == 0) {
dp[i][j] = i;
} else {
dp[i][j] = Math.min(
dp[i - 1][j - 1] + (word1.charAt(i - 1) == word2.charAt(j - 1) ? 0 : 1),
Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1)
);
}
}
}
return dp[m][n];
}
}
四、总结小记
- 2022/7/4 坚持每天一题
边栏推荐
- 历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享
- 做BI开发,为什么一定要熟悉行业和企业业务?
- QT - plot other problems
- 面试题 01.08. 零矩阵
- 网上开户哪家证券公司佣金最低,我要开户,网上开户安全吗
- 案例分享|金融业数据运营运维一体化建设
- 【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
- 股票开户流程是什么?使用同花顺手机炒股软件安全吗?
- Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
- bizchart+slider实现分组柱状图
猜你喜欢
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
保证接口数据安全的10种方案
抖音实战~评论数量同步更新
The use of complex numbers in number theory and geometry - Cao Zexian
Operation of adding material schedule in SolidWorks drawing
PMO:比较25种分子优化方法的样本效率
力扣98:验证二叉搜索树
卷积神经网络模型之——LeNet网络结构与代码实现
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享
随机推荐
什么是商业智能(BI),就看这篇文章足够了
关系型数据库
时空预测3-graph transformer
Interviewer: what is XSS attack?
GTEST from ignorance to skillful use (1) GTEST installation
How much is the minimum stock account opening commission? Is it safe to open an account online
283. 移动零-c与语言辅助数组法
ACM multimedia 2022 | counterfactual measurement and elimination of social prejudice in visual language pre training model
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
HDU - 2859 Phalanx(DP)
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
Flink1.13 SQL basic syntax (I) DDL, DML
Enlightenment of maker thinking in Higher Education
VS2019 C# release下断点调试
PMO:比较25种分子优化方法的样本效率
力扣3_383. 赎金信
How to remove the black dot in front of the title in word document
TLA+ 入门教程(1):形式化方法简介
vim 从嫌弃到依赖(23)——最后的闲扯