当前位置:网站首页>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
边栏推荐
- About Random Numbers
- Custom MVC (imported into jar package) + difference from three-tier architecture + reflection + interview questions
- From bitmap to bloom filter, C # implementation
- What are the skills and methods for slip ring installation
- Keepalived 实现 Redis AutoFailover (RedisHA)14
- Lwip之定时机制
- At present, which securities company is the best and safest to open an account for stock speculation?
- memcached基础5
- 统计无向图中无法互相到达点对数[经典建邻接表+DFS统计 -> 并查集优化][并查集手册/写的详细]
- C#程序结构预览最基础入门
猜你喜欢

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

Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)

简单快速的数网络(网络中的网络套娃)

3 - wire SPI Screen Drive

Network in network (dolls)

Solve the problem that only one line of text is displayed or not displayed in u8glib

Simple and fast digital network (network dolls in the network)

Pet hospital management system based on SSMP

Sword finger offer 10- ii Frog jumping on steps

Oracle 數據庫基本知識概念
随机推荐
Keepalived 实现 Redis AutoFailover (RedisHA)16
寻找旋转排序数组中的最小值 II[经典抽象二分 + 如何破局左中右三者相等]
世界很大,有人把二维码纹在脖子上
Is it safe for CITIC Securities Commission to open an online account and speculate in stocks
ESP32-添加多目录的自定义组件
Sword finger offer 10- ii Frog jumping on steps
2022 Health Expo, Shandong health care exhibition, postpartum health and sleep health exhibition
Redis detailed tutorial
大白话高并发(一)
Lwip之ARP模块实现
目前哪个证券公司炒股开户是最好最安全的?
memcached基础1
Overview of Freescale MCU
Xiaobai looks at MySQL -- installing MySQL in Windows Environment
memcached基础
buuctf-pwn write-ups (6)
Is it safe to open a securities account online? Is it reliable to speculate in stocks by mobile phone
解决u8glib只显示一行文字或者不显示的问题
Esp32 add multi directory custom component
【Mysql】时间字段默认设置为当前时间