当前位置:网站首页>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
边栏推荐
- PHP short video source code, thumb animation will float when you like it
- 卷积神经网络模型之——LeNet网络结构与代码实现
- LOGO特训营 第三节 首字母创意手法
- 并发优化总结
- Basic structure of PostgreSQL - table
- 1807. Replace the parentheses in the string
- odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
- Force buckle_ Palindrome number
- More than 30 institutions jointly launched the digital collection industry initiative. How will it move forward in the future?
- 迷失在Mysql的锁世界
猜你喜欢
i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
Bizchart+slider to realize grouping histogram
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
力扣98:验证二叉搜索树
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
More than 30 institutions jointly launched the digital collection industry initiative. How will it move forward in the future?
SPSS安装激活教程(包含网盘链接)
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
Kdd2022 | what features are effective for interaction?
随机推荐
删库不必跑路!详解 MySQL 数据恢复
Logo special training camp section 1 Identification logo and logo design ideas
[advanced C language] array & pointer & array written test questions
What is the stock account opening process? Is it safe to use flush mobile stock trading software?
Tiktok actual combat ~ the number of comments is updated synchronously
Mysql root 账号如何重置密码
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
短视频系统源码,点击屏幕空白处键盘不自动收起
力扣_回文数
The use of complex numbers in number theory and geometry - Cao Zexian
Implementation rules for archiving assessment materials of robot related courses 2022 version
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency
1807. 替换字符串中的括号内容
Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
常用的开源无代码测试工具
凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
Postgresqlql advanced skills pivot table
# 2156. 查找给定哈希值的子串-后序遍历
Relational database
Jvm-Sandbox-Repeater的部署