题解 | #公共子串计算#

公共子串计算

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);

全部评论

相关推荐

不愿透露姓名的神秘牛友
02-16 22:33
杉川机器人 嵌入式工程师 18.0k*13.0, 年终奖1~9个月浮动
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务