#476 Number Complement

题目:

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.



代码:

/**

* @param {number} num

* @return {number}

*/

var findComplement = function(num) {

var n = 1;

while (n <= num) {

n *= 2

}

return ((n - 1) ^ num);

};

你可能感兴趣的:(#476 Number Complement)