Javascript solution without loop, bit manipulation


  • 0
    var findComplement = function(num) {
        let mask = () => {
            let t = Math.floor(Math.log2(num)) + 1;
            return Math.pow(2, t) - 1;    
        };
        return mask(num) ^ num;
    };
    

Log in to reply
 

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