{"size": 978, "ext": "js", "max_stars_repo_path": "problems/476-number-complement/index.js", "max_stars_repo_name": "shudery/leetCode", "max_stars_repo_stars_event_min_datetime": "2018-03-14T15:46:00.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-15T03:13:41.000Z", "max_issues_repo_path": "problems/476-number-complement/index.js", "max_issues_repo_name": "shudery/leetCode", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problems/476-number-complement/index.js", "max_forks_repo_name": "shudery/leetCode", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.6, "max_line_length": 129, "alphanum_fraction": 0.6646216769}
// Title  : number-complement
// Date   : 2017-03-10
// Author : Daguo
/*****************************************
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.

Note:
The given integer is guaranteed to fit within the range of a 32-bit signed integer.
You could assume no leading zero bit in the integer’s binary representation.
Example 1:
Input: 5
Output: 2
Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
Example 2:
Input: 1
Output: 0
Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
*****************************************/
/**
 * @param {number} num
 * @return {number}
 */
var findComplement = function(num) {
  var len = num.toString(2).length;
  var n = Math.pow(2, len) - 1;
  return num ^ n;
};

module.exports = [findComplement];
