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.
2 parents badc437 + 927c786 commit 0e20476Copy full SHA for 0e20476
javascript/1143-Longest-Common-Subsequence.js
@@ -0,0 +1,17 @@
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
+ table[i][j] = Math.max(table[i - 1][j], table[i][j - 1]);
11
+ } else {
12
+ table[i][j] = table[i - 1][j - 1] + 1;
13
+ }
14
15
16
+ return table[m][n];
17
+};
0 commit comments