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 d9d562f commit 78a7ea0Copy full SHA for 78a7ea0
javascript/1143-Longest-Common-Subsequence.js
@@ -0,0 +1,18 @@
1
+var longestCommonSubsequence = function (text1, text2) {
2
+ let m = text1.length;
3
+ let n = text2.length;
4
+
5
+ let table = new Array(m + 1).fill().map(() => new 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.charAt(i - 1) !== text2.charAt(j - 1)) {
10
11
+ table[i][j] = Math.max(table[i - 1][j], table[i][j - 1]);
12
+ } else {
13
+ table[i][j] = table[i - 1][j - 1] + 1;
14
+ }
15
16
17
+ return table[m][n];
18
+};
0 commit comments