You are viewing a single comment's thread. Return to all comments →
Typescript Solution
const commonChild = (s1: string, s2: string): number => { const m = s1.length; const n = s2.length; // @ts-ignore const matrix: number[][] = Array.from({length: m + 1}, () => Array(n + 1).fill(0)); let longestChild = matrix[0][0]; for (let i = 1; i <= m; i++) { for (let j = 1; j <= n; j++) { if (s1[i - 1] === s2[j - 1]) { matrix[i][j] = matrix[i - 1][j - 1] + 1; } else { matrix[i][j] = Math.max(matrix[i - 1][j], matrix[i][j - 1]); } if (matrix[i][j] > longestChild) { longestChild = matrix[i][j]; } } } return longestChild; }
Seems like cookies are disabled on this browser, please enable them to open this website
Common Child
You are viewing a single comment's thread. Return to all comments →
Typescript Solution