0 喜欢

【每日一题】算法之最长回文子串

admin
admin
2020-11-03 11:19:22 阅读 1437

LeetCode地址

最长回文子串

算法难度

中等

JS代码

/** * @param {string} s * @return {string} */ var longestPalindrome = function(s) { let left = 0 let index = 0 let right = 0 let max = 0 let start = 0 let len = s.length while(index < len) { left = index - 1 right = index while(s[right] === s[index]) { right++ } index = right while(left >= 0 && right < len && s[right] === s[left]) { right++ left-- } if (right - left - 1 > max) { max = right - left - 1 start = left + 1 } } return s.substr(start, max) };

关于作者
admin
admin
admin@ifront.net
 获得点赞 173
 文章阅读量 215308