题解 | #公共子串计算#
公共子串计算
https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
let str1 = readline(); let str2 = readline(); let max = 0; let short; let long; short = str1.length >= str2.length ? str2 : str1; long = str1.length >= str2.length ? str1 : str2; for(let i = short.length;i>=1;i--){ for(let j = 0;j+i<=short.length;j++){ if(long.includes(short.substr(j,i))){ max = Math.max(max,short.substr(j,i).length); } } } console.log(max);