5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example 1:
Example 2:
解题要点:
一个dp 2d array来存i,j是否为回文,同时在遍历时需要检测头尾是否为一样字符,里面的字符是否为回文(长度小于等于2的默认为回文),如果是,把当前dp位置的i,j改为True,此位置是回文,并记录最大回文index,最后返回记录好的index。
Last updated
Was this helpful?