题解 | #密码截取#

密码截取

https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1

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 s = line.length;
        let maxLength = 0;
        for (let i = 0; i < 2*s -1; i++) {
            let start = Math.floor(i / 2), end = Math.ceil(i / 2)
            // console.log(i, start, end)
            while (start <= end && start >= 0 && end < s 
                && line.charAt(start) ===  line.charAt(end)) {
                    maxLength = Math.max(maxLength, end - start + 1);
                    // console.log(start, end, maxLength, '-----') 
                    start--;
                    end++;
                }
        }
        console.log(maxLength)
    }
}()

全部评论

相关推荐

LazyBreeze:项目尽量体现你对技术的理解和深度,不是说把中间件用一下就完事了,你项目里面提到集群和分布式,你真在服务器上部署过吗,感觉太假了,第二个项目说自己用了微服务的什么组件,只是用了没有自己的思考,很难让面试官注意到你的简历。针对某几个技术点自己多思考一下,考虑一下有没有别的替代方案,可以写一下,即使没有真的实现
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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