当前位置:网站首页>leetcode 72. Edit distance edit distance (medium)
leetcode 72. Edit distance edit distance (medium)
2022-07-04 22:29:00 【InfoQ】
One 、 The main idea of the topic
- 0 <= word1.length, word2.length <= 500
- word1 and word2 It's made up of lowercase letters
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
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];
}
}
Four 、 Summary notes
- 2022/7/4 Stick to one question every day
边栏推荐
- Basic structure of PostgreSQL - table
- 保证接口数据安全的10种方案
- sqlserver对数据进行加密、解密
- 1807. 替换字符串中的括号内容
- How to transfer to software testing, one of the high paying jobs in the Internet? (software testing learning roadmap attached)
- Representation of confidence interval
- 复数在数论、几何中的用途 - 曹则贤
- 《命令行上的数据科学第二版》校对活动重新启动
- Scala下载和配置
- Energy momentum: how to achieve carbon neutralization in the power industry?
猜你喜欢
并发优化总结
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
机器学习笔记 - 互信息Mutual Information
[acwing] solution of the 58th weekly match
Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
TCP protocol three times handshake process
抖音实战~评论数量同步更新
Use blocconsumer to build responsive components and monitor status at the same time
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
随机推荐
PostgreSQLSQL高级技巧透视表
广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency
283. 移动零-c与语言辅助数组法
MySQL存储数据加密
Easy to use app recommendation: scan QR code, scan barcode and view history
Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
Machine learning notes mutual information
Solana链上应用Crema因黑客攻击停运
凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
傳智教育|如何轉行互聯網高薪崗比特之一的軟件測試?(附軟件測試學習路線圖)
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
能源势动:电力行业的碳中和该如何实现?
leetcode 72. Edit Distance 编辑距离(中等)
【C语言进阶篇】数组&&指针&&数组笔试题
The proofreading activity of data science on the command line second edition was restarted
Service online governance