parsing

Solution 1: center diffusion method

/ * * *@param {string} s
 * @return {string}* /
// Center diffusion method
var longestPalindrome = function(s) {
    let len = s.length
    if (s.length<2) {return s
    }
    let res = ""
    for(let i = 0; i < len; i++){/ / odd string
        findstr(i,i)
        / / even string
        findstr(i,i+1)}function findstr(m,n){
        // Start from the midline and spread out to both sides
        while(m >= 0 && n < len && s[m] === s[n]){
            m--
            n++
        }
        // Note point 1: the final end of the boundary m,n is exactly one more than we want all the correct boundaries are m+1 n-1
        // Note 2: The actual string length is n-m-1
        if(n-m-1 > res.length){
            res = s.slice(m+1,n)
        }
    }
    return res
};
Copy the code

Method 2: Dynamic programming method (to be determined)