Simple JavaScript Solution


  • 1
    T
    /**
     * @param {number} num
     * @return {number}
     */
    var findComplement = function(num) {
        num = num.toString(2).replace(/[0|1]/g, function (match) {
            return Number(match) ^ 1;
        });
        
        return parseInt(num, 2);
    };
    

Log in to reply
 

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