题解 | #公共子串计算#

公共子串计算

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

全部评论

相关推荐

05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务