当前位置:网站首页>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 明天周一,继续加油
边栏推荐
- Find the minimum value in the rotation sort array ii[classical Abstract dichotomy + how to break the game left, middle and right are equal]
- Unable to create a folder to save the sketch: MKDIR sketch
- 史上最难618,TCL夺得电视行业京东和天猫份额双第一
- 3线spi屏幕驱动方式
- CEC-I 中华学习机使用说明与问答
- 一键加速索尼相机SD卡文件的复制操作,文件操作批处理教程
- memcached基础
- Keepalived 实现 Redis AutoFailover (RedisHA)15
- 大白话高并发(一)
- 30《MySQL 教程》MySQL 存储引擎概述
猜你喜欢

Central Limit Theorem

2022年地理信息系统与遥感专业就业前景与升学高校排名选择

解决u8glib只显示一行文字或者不显示的问题

Flink 实战问题(七):No Watermark(Watermarks are only available EventTime is used)

Bootstrapblazor + FreeSQL actual combat chart usage (2)

CH423要如何使用,便宜的国产IO扩展芯片
![Custom jsp[if, foreach, data, select] tag](/img/a2/fc75c182d572d86f4466323e31d6c3.png)
Custom jsp[if, foreach, data, select] tag

Hid device descriptor and keyboard key value corresponding coding table in USB protocol

Buuctf PWN write UPS (6)

解决unable to create a folder to save the sketch: mkdir sketch
随机推荐
2022健康博览会,山东养生保健展会,产后健康、睡眠健康展
滑环选型选购时需要注意的技巧
Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
Central Limit Theorem
直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)
How to use ch423? Cheap domestic IO expansion chip
Operating instructions and Q & A of cec-i China learning machine
解决u8glib只显示一行文字或者不显示的问题
滑环安装有哪些技巧和方法
Processing of slice loss in ArcGIS mosaic dataset
Simple and fast digital network (network dolls in the network)
JSON parsing, esp32 easy access to time, temperature and weather
寻找旋转排序数组中的最小值 II[经典抽象二分 + 如何破局左中右三者相等]
自定义MVC(导成jar包)+与三层架构的区别+反射+面试题
Esp32 add multi directory custom component
Gaussian and Summary Stats
BootstrapBlazor + FreeSql实战 Chart 图表使用(2)
目前哪个证券公司炒股开户是最好最安全的?
网上开通证券账户安全吗 手机炒股靠谱吗