当前位置:网站首页>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
边栏推荐
- Recommendation of mobile app for making barcode
- HBuilder X 常用的快捷键
- i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
- Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
- 制作条形码的手机App推荐
- TCP protocol three times handshake process
- How can the advertising system of large factories be upgraded without the presence of large models
- WebGIS框架---kalrry
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
猜你喜欢

虚拟人产业面临的挑战

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

抖音实战~评论数量同步更新

BigFilter全局交易防重组件的介绍与应用

UML图记忆技巧

30余家机构联合发起数字藏品行业倡议,未来会如何前进?

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

LOGO特訓營 第三節 首字母創意手法

Huawei Nova 10 series released Huawei application market to build a solid application security firewall

HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
随机推荐
如何实现轻松管理1500万员工?
Alibaba launched a new brand "Lingyang" and is committed to becoming a "digital leader"
面试题 01.08. 零矩阵
现在mysql cdc2.1版本在解析值为0000-00-00 00:00:00的datetime类
SPSS安装激活教程(包含网盘链接)
TLA+ 入门教程(1):形式化方法简介
Interview question 01.08 Zero matrix
删库不必跑路!详解 MySQL 数据恢复
HBuilder X 常用的快捷键
【C语言进阶篇】数组&&指针&&数组笔试题
Deployment of JVM sandbox repeater
Postgresqlql advanced skills pivot table
制作条形码的手机App推荐
How diff are the contents of the same configuration item in different environments?
The drawing method of side-by-side diagram, multi row and multi column
国产数据库乱象
力扣98:验证二叉搜索树
2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { fmt.Pri
1807. Replace the parentheses in the string
Mysql root 账号如何重置密码