当前位置:网站首页>leetcode 1143. Longest common subsequence (medium)
leetcode 1143. Longest common subsequence (medium)
2022-06-27 00:59:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= text1.length, text2.length <= 1000
- text1 and text2 It only consists of lowercase English characters .
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
public class Solution {
public int longestCommonSubsequence(String text1, String text2) {
int m = text1.length();
int n = text2.length();
// Indicates to the first string position i until 、 To the second string position j until 、 The longest common subsequence length
int[][] dp = new int[m + 1][n + 1];
for (int i = 1; i < m + 1; i++) {
for (int j = 1; j < n + 1; j++) {
if (text1.charAt(i - 1) == text2.charAt(j - 1)) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
return dp[m][n];
}
}
Four 、 Summary notes
- 2022/6/26 Tomorrow Monday , Continue refueling
边栏推荐
猜你喜欢
2022年地理信息系统与遥感专业就业前景与升学高校排名选择
What is the difference between the working principle of gas-liquid slip ring and other slip rings
Solve the problem that stc8g1k08 program cannot run and port configuration
Buuctf PWN write UPS (6)
ESP32实验-自建web服务器配网02
BootstrapBlazor + FreeSql实战 Chart 图表使用(2)
Batch generate folders based on file names
墨者学院-X-Forwarded-For注入漏洞实战
Gaussian and Summary Stats
滑环选型选购时需要注意的技巧
随机推荐
滑环安装有哪些技巧和方法
C#程序结构预览最基础入门
世界很大,有人把二维码纹在脖子上
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
Keepalived 实现 Redis AutoFailover (RedisHA)11
BootstrapBlazor + FreeSql实战 Chart 图表使用(2)
光谱共焦如何测量玻璃基板厚度
Lambda expression
统计无向图中无法互相到达点对数[经典建邻接表+DFS统计 -> 并查集优化][并查集手册/写的详细]
From bitmap to bloom filter, C # implementation
07 | 工作流设计:如何设计合理的多人开发模式?
ESP32实验-自建web服务器配网02
Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
基于SSMP的宠物医院管理系统
Gaussian and Summary Stats
Keepalived 实现 Redis AutoFailover (RedisHA)17
Overview of Freescale MCU
Great health industry annual must attend event, 2022 Shandong International Great Health Industry Expo
What is the difference between the working principle of gas-liquid slip ring and other slip rings
建模规范:环境设置