题解 | #密码截取#
密码截取
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; const f = (s) => { const length = s.length; let max = 0; for (let i = 0; i < length ; i++) { for (let j = length-1; j >=0 ; j--) { if(s[i]==s[j]){ let index = 0; let a=[]; for(let m=i,n=j;s[m]==s[n]&&(n>=0&&m<length);m++,n--){ index++; a.push(s[m]) } if(index>max&&a.join("")==a.reverse().join("")){ max=index; } } } } return max; }; void (async function () { while ((line = await readline())) { console.log(f(line)); } })();