728x90
const LCS = function (str1, str2) {
const N = str1.length;
const M = str2.length;
const d = Array.from(Array(N+3), () => Array(M+3).fill(0));
for (let i = 1; i <= N; i++) {
for (let j = 1; j <= M; j++) {
if(str1[i-1] === str2[j-1]) d[i][j] = d[i-1][j-1]+1;
else d[i][j] = Math.max(d[i-1][j], d[i][j-1]);
}
}
return d[N][M];
}반응형
'BEB > algorithm' 카테고리의 다른 글
| 38_decompression (0) | 2022.12.16 |
|---|---|
| 37_coinChange (0) | 2022.12.15 |
| 33 LIS (Longest Increasing Sequence) 가장 긴 증가하는 수열 (0) | 2022.12.09 |
| 백준6549 javascript 히스토그램, 32_largestRectangularArea (0) | 2022.12.08 |
| 29 binary heap 최대힙 (1) | 2022.12.05 |
댓글