Neat Javascript Solution


  • 0
    D
    var canPermutePalindrome = function(s) {
        const charset = {};
        
        // maintain a set of charactors that occur odd number of times
        for (var c of s) {
            if (charset[c]) delete charset[c];
            else charset[c] = 1;
        }
        
        // return true if zero or one charactor that occur odd number of times
        return Object.keys(charset).length <= 1 ? true : false;
    };
    
    

Log in to reply
 

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