题解 | #查找两个字符串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 () {
// Write your code here
// while(line = await readline()){
// let tokens = line.split(' ');
// let a = parseInt(tokens[0]);
// let b = parseInt(tokens[1]);
// console.log(a + b);
// }
let a = await readline();
let b = await readline();
if (a.length > b.length) {
[a, b] = [b, a];
}
let res = "";
let j = 1;
let i = 0;
while(i < a.length && j < a.length + 1) {
let temp = a.slice(i, j);
if(b.indexOf(temp) > -1) {
res = temp.length > res.length ? temp : res;
j++
} else {
i++;
j = i + 1;
}
}
console.log(res);
})();
