当前位置:网站首页>leetcode 1143. Longest Commom Subsequence 最长公共子序列(中等)
leetcode 1143. Longest Commom Subsequence 最长公共子序列(中等)
2022-06-27 00:33:00 【InfoQ】
一、题目大意
- 1 <= text1.length, text2.length <= 1000
- text1 和 text2 仅由小写英文字符组成。
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public int longestCommonSubsequence(String text1, String text2) {
int m = text1.length();
int n = text2.length();
// 表示到第一个字符串位置i为止、到第二个字符串位置j为止、最长的公共子序列长度
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];
}
}
四、总结小记
- 2022/6/26 明天周一,继续加油
边栏推荐
- 光谱共焦如何测量玻璃基板厚度
- Account management, database building and four engines + cases of MySQL
- Lwip之ARP模块实现
- ArcGIS 镶嵌数据集切片丢失问题处理
- How to control the quality of HD slip ring in the production process
- 滑环选型选购时需要注意的技巧
- 05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
- How to use ch423? Cheap domestic IO expansion chip
- ESP32-SOLO开发教程,解决CONFIG_FREERTOS_UNICORE问题
- 从位图到布隆过滤器,C#实现
猜你喜欢
Review the old and know the new -- constant renewal at normal temperature
Gaussian and Summary Stats
buuctf-pwn write-ups (6)
Network in network (dolls)
Solve the problem that stc8g1k08 program cannot run and port configuration
Statistical Hypothesis Testing
Processing of slice loss in ArcGIS mosaic dataset
Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
Other service registration and discovery
剑指 Offer 10- II. 青蛙跳台阶问题
随机推荐
Gaussian and Summary Stats
剑指 Offer 10- II. 青蛙跳台阶问题
Concepts de base de données Oracle
JS library for number formatting
大白话高并发(一)
记录一次换行符引起的bug
Database interview questions +sql statement analysis
光谱共焦如何测量玻璃基板厚度
Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
ESP32实验-自建web服务器配网02
Is it safe to open a compass account?
The most difficult 618 in history, TCL won the first place in both jd.com and tmall.com shares in the TV industry
memcached基础4
Beyond lithium battery -- the concept of battery in the future
墨者学院-SQL注入漏洞测试(报错盲注)
玩转OLED,U8g2动画,增长数字和随机三角形等
Redis detailed tutorial
一键加速索尼相机SD卡文件的复制操作,文件操作批处理教程
Is there anyone who doesn't know the three cores of concurrent programming?
自定义MVC(导成jar包)+与三层架构的区别+反射+面试题