题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", function (line) { solution(line); }); let maxLen = 0; function solution(line: string) { for (let index = 0; index < line.length; index++) { const element = line[index]; expand([index, index + 1], line); expand([index, index + 2], line); } console.log(maxLen); } function expand([start, end]: [number, number], line: string) { if (!(start >= 0 && end <= line.length)) { return; } let subStr = line.substring(start, end); let subStrReversed = subStr.split("").reverse().join(""); if (subStr === subStrReversed) { maxLen = Math.max(maxLen, subStr.length); return expand([start - 1, end + 1], line); } }#递归#