当前位置:网站首页>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
边栏推荐
- How to write test cases and a brief introduction to go unit test tool testify
- Encapsulation of unified result set
- 光谱共焦如何测量玻璃基板厚度
- 统一结果集的封装
- 数据库面试题+sql语句解析
- What is the difference between the working principle of gas-liquid slip ring and other slip rings
- Law of Large Numbers
- How to measure the thickness of glass substrate by spectral confocal
- 记录一次换行符引起的bug
- 07 | workflow design: how to design a reasonable multi person development mode?
猜你喜欢

ESP32-SOLO开发教程,解决CONFIG_FREERTOS_UNICORE问题

C#程序结构预览最基础入门

【Mysql】时间字段默认设置为当前时间

Skills needing attention in selection and purchase of slip ring

How to control the quality of HD slip ring in the production process

一键加速索尼相机SD卡文件的复制操作,文件操作批处理教程

CPU exception handling

3-wire SPI screen driving mode

05 | 規範設計(下):commit 信息風格迥异、難以閱讀,如何規範?

The world is very big. Some people tattoo QR codes on their necks
随机推荐
LeetCode 142. 环形链表 II
Buuctf PWN write UPS (6)
滑环安装有哪些技巧和方法
CPU exception handling
墨者学院-SQL注入漏洞测试(报错盲注)
ESP32-添加多目录的自定义组件
XML learning notes
Is it safe to open a compass account?
直播回顾 | 子芽&CCF TF:云原生场景下软件供应链风险治理技术浅谈
Keepalived 实现 Redis AutoFailover (RedisHA)17
Solution of idea hot start failure
BootstrapBlazor + FreeSql实战 Chart 图表使用(2)
Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario
05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
Keepalived 实现 Redis AutoFailover (RedisHA)16
How to write test cases and a brief introduction to go unit test tool testify
根据文件名批量生成文件夹
Solve the problem that only one line of text is displayed or not displayed in u8glib
Solve the problem that stc8g1k08 program cannot run and port configuration
At present, which securities company is the best and safest to open an account for stock speculation?