题目:
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);
};
网友评论