题解 | #最长回文子串#
最长回文子串
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”,某博客继续更新。

