You are viewing a single comment's thread. Return to all comments →
js
function commonChild(s1, s2) { let prevRow; for (const char1 of s1) { const curRow = []; let last = 0; let ind = 0; for (const char2 of s2) { let length; if (char1 === char2) { length = (prevRow?.[ind - 1] ?? 0) + 1; } else { length = Math.max( last, prevRow?.[ind] ?? 0 ); } curRow.push(length); last = length; ind++; } prevRow = curRow; } return prevRow?.pop() ?? 0; }
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 →
js