当前位置:网站首页>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
边栏推荐
- Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
- Alibaba launched a new brand "Lingyang" and is committed to becoming a "digital leader"
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- 机器人相关课程考核材料归档实施细则2022版本
- PostgreSQLSQL高级技巧透视表
- 迷失在Mysql的锁世界
- TCP protocol three times handshake process
- 面试题 01.01. 判定字符是否唯一
- Implementation rules for archiving assessment materials of robot related courses 2022 version
- Domestic database chaos
猜你喜欢

Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry

玩转gRPC—深入概念与原理

湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章

With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu

并发优化总结

close系统调用分析-性能优化

Introduction and application of bigfilter global transaction anti duplication component

UML diagram memory skills

The use of complex numbers in number theory and geometry - Cao Zexian

凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
随机推荐
LOGO特训营 第二节 文字与图形的搭配关系
How can the advertising system of large factories be upgraded without the presence of large models
From repvgg to mobileone, including mobileone code
PostgreSQL server programming aggregation and grouping
LOGO特训营 第一节 鉴别Logo与Logo设计思路
BigFilter全局交易防重组件的介绍与应用
服装企业为什么要谈信息化?
WebGIS框架---kalrry
湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
leetcode 72. Edit Distance 编辑距离(中等)
短视频系统源码,点击屏幕空白处键盘不自动收起
Force buckle 3_ 383. Ransom letter
面试题 01.08. 零矩阵
卷积神经网络模型之——LeNet网络结构与代码实现
《命令行上的数据科学第二版》校对活动重新启动
Concurrent optimization summary
High school physics: linear motion
Shell 脚本实现应用服务日志入库 Mysql
Implementation rules for archiving assessment materials of robot related courses 2022 version
odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数