题解 | #查找两个字符串a,b中的最长公共子串#
查找两个字符串a,b中的最长公共子串
https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { const str1 = await readline(); const str2 = await readline(); const [longStr,shortStr] = str1.length > str2.length?[str1,str2]:[str2,str1]; const len = shortStr.length; for(let i = len; i > 0; i--){ for(j = 0; j + i <= len; j++){ if(longStr.includes(shortStr.substring(j,j+i))) return console.log(shortStr.substring(j,j+i)); } } }()