当前位置:网站首页>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
边栏推荐
- Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
- Detailed explanation of flask context
- 如何实现轻松管理1500万员工?
- MySQL storage data encryption
- [advanced C language] array & pointer & array written test questions
- Bizchart+slider to realize grouping histogram
- 我在linux里面 通过调用odspcmd 查询数据库信息 怎么静默输出 就是只输出值 不要这个
- 力扣_回文数
- More than 30 institutions jointly launched the digital collection industry initiative. How will it move forward in the future?
- Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
猜你喜欢
Use blocconsumer to build responsive components and monitor status at the same time
LOGO特训营 第三节 首字母创意手法
保证接口数据安全的10种方案
[acwing] solution of the 58th weekly match
From repvgg to mobileone, including mobileone code
LOGO special training camp section I identification logo and Logo Design Ideas
Tiktok actual combat ~ the number of comments is updated synchronously
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
UML diagram memory skills
随机推荐
1807. Replace the parentheses in the string
Relational database
VIM from dislike to dependence (23) -- the last gossip
Implementation rules for archiving assessment materials of robot related courses 2022 version
Common shortcut keys for hbuilder x
From repvgg to mobileone, including mobileone code
Jvm-Sandbox-Repeater的部署
Recommendation of mobile app for making barcode
[advanced C language] array & pointer & array written test questions
微服务--开篇
LOGO特训营 第一节 鉴别Logo与Logo设计思路
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
面试题 01.01. 判定字符是否唯一
LOGO special training camp section I identification logo and Logo Design Ideas
HBuilder X 常用的快捷键
Force buckle 3_ 383. Ransom letter
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
不同环境相同配置项的内容如何diff差异?
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
WebGIS framework -- kalrry