We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b7ff251 commit 471cb16Copy full SHA for 471cb16
longest-common-subsequence/hyer0705.ts
@@ -0,0 +1,18 @@
1
+function longestCommonSubsequence(text1: string, text2: string): number {
2
+ const m = text1.length;
3
+ const n = text2.length;
4
+
5
+ const dp: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
6
7
+ for (let i = 1; i <= m; i++) {
8
+ for (let j = 1; j <= n; j++) {
9
+ if (text1[i - 1] === text2[j - 1]) {
10
+ dp[i][j] = dp[i - 1][j - 1] + 1;
11
+ } else {
12
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
13
+ }
14
15
16
17
+ return dp[m][n];
18
+}
0 commit comments