Javascript Solution


  • 0
    H

    use sort

    /**
     * @param {string} s
     * @return {number}
     */
    var longestPalindrome = function(s) {
        var count=0;
        var m=s.split("");
        m.sort();
        for(var i=0;i<m.length-1;i++)
        {
            if(m[i]===m[i+1])
            {
                count+=2;
                m.splice(i,2);
                i--;
            }
        }
        if(m.length>0) count++;
        return count;
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.