题解 | #密码截取#
密码截取
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) } }()