当前位置:网站首页>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 明天周一,继续加油
边栏推荐
- USB协议中HID设备描述符以及键盘按键值对应编码表
- Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)
- 论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
- Account management, database building and four engines + cases of MySQL
- 30《MySQL 教程》MySQL 存储引擎概述
- 2022 Health Expo, Shandong health care exhibition, postpartum health and sleep health exhibition
- Custom jsp[if, foreach, data, select] tag
- At present, which securities company is the best and safest to open an account for stock speculation?
- find_circ详细使用指南
- JSON解析,ESP32轻松获取时间气温和天气
猜你喜欢
![Find the minimum value in the rotation sort array ii[classical Abstract dichotomy + how to break the game left, middle and right are equal]](/img/75/05d5765588dfde971167fbc72e2aa8.png)
Find the minimum value in the rotation sort array ii[classical Abstract dichotomy + how to break the game left, middle and right are equal]

07 | 工作流设计:如何设计合理的多人开发模式?

Unable to create a folder to save the sketch: MKDIR sketch

In depth understanding of UDP in the transport layer and the use of UDP in sockets

buuctf-pwn write-ups (6)
![Custom jsp[if, foreach, data, select] tag](/img/a2/fc75c182d572d86f4466323e31d6c3.png)
Custom jsp[if, foreach, data, select] tag

Other service registration and discovery

解决unable to create a folder to save the sketch: mkdir sketch

Oracle database basics concepts

ESP32-SOLO开发教程,解决CONFIG_FREERTOS_UNICORE问题
随机推荐
One click acceleration of Sony camera SD card file copy operation, file operation batch processing tutorial
基于SSMP的宠物医院管理系统
Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
memcached基础6
JS library for number formatting
Solve the problem that only one line of text is displayed or not displayed in u8glib
05 | 規範設計(下):commit 信息風格迥异、難以閱讀,如何規範?
大白话高并发(一)
Sword finger offer 10- ii Frog jumping on steps
memcached基础
Statistical Hypothesis Testing
How to control the quality of HD slip ring in the production process
Great health industry annual must attend event, 2022 Shandong International Great Health Industry Expo
Beyond lithium battery -- the concept of battery in the future
At present, which securities company is the best and safest to open an account for stock speculation?
统一结果集的封装
Bootstrapblazor + FreeSQL actual combat chart usage (2)
Law of Large Numbers
剑指 Offer 10- II. 青蛙跳台阶问题