题解 | #最长回文子串#

最长回文子串

https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    const str = await readline();
    if(str.length == 1) return console.log(1)
    const dfs = (i,j) => {
        while(i>=0 && j<str.length && str[i]===str[j]) {
            i--;
            j++;
        }
        // console.log(i,j);
        return j-i-1;
    }
    let max = 0;
    for(let i = 0; i < str.length; i++){
        max = Math.max(max,dfs(i,i),dfs(i,i+1));
    }
    console.log(max);
}()

华为OD,我昵称“od400” 文章被收录于专栏

华为OD机试刷题历程,因涉及华为权益,牛客不允许更新了。我昵称“od400”,某博客继续更新。

全部评论

相关推荐

2024-12-18 14:13
蚌埠坦克学院 golang
苏州科技大学:面试官:接个面试,对面同学是个杀软二次元
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务