当前位置:网站首页>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
边栏推荐
- Force buckle_ Palindrome number
- Shell script implements application service log warehousing MySQL
- 【C语言进阶篇】数组&&指针&&数组笔试题
- sqlserver对数据进行加密、解密
- Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
- 迷失在Mysql的锁世界
- Convolutional neural network model -- lenet network structure and code implementation
- 虚拟人产业面临的挑战
- 高中物理:直线运动
- odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
猜你喜欢

Introduction and application of bigfilter global transaction anti duplication component

How to transfer to software testing, one of the high paying jobs in the Internet? (software testing learning roadmap attached)

Domestic database chaos

2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri

Convolutional neural network model -- lenet network structure and code implementation

Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game

保证接口数据安全的10种方案

LOGO特训营 第二节 文字与图形的搭配关系

SPSS安装激活教程(包含网盘链接)

A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
随机推荐
将QA引入软件开发生命周期是工程师要遵循的最佳实践
HBuilder X 常用的快捷键
Play with grpc - go deep into concepts and principles
VIM from dislike to dependence (23) -- the last gossip
达梦数据凭什么被称为国产数据库“第一股”?
《命令行上的数据科学第二版》校对活动重新启动
Short video system source code, click the blank space of the screen, the keyboard does not automatically stow
Concurrent optimization summary
面试必备 LeetCode 链表算法题汇总,全程干货!
MySQL storage data encryption
Interview question 01.08 Zero matrix
短视频系统源码,点击屏幕空白处键盘不自动收起
传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
大厂的广告系统升级,怎能少了大模型的身影
【Acwing】第58场周赛 题解
LOGO特訓營 第三節 首字母創意手法
[acwing] solution of the 58th weekly match
WebGIS框架---kalrry