Skip to content

Commit 820ffe6

Browse files
committed
Add solution #1009
1 parent 7a06032 commit 820ffe6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 1009. Complement of Base 10 Integer
3+
* https://leetcode.com/problems/complement-of-base-10-integer/
4+
* Difficulty: Easy
5+
*
6+
* Every non-negative integer N has a binary representation.
7+
* For example, 5 can be represented as "101" in binary,
8+
* 11 as "1011" in binary, and so on. Note that except for
9+
* N = 0, there are no leading zeroes in any binary representation.
10+
*
11+
* The complement of a binary representation is the number in binary
12+
* you get when changing every 1 to a 0 and 0 to a 1. For example,
13+
* the complement of "101" in binary is "010" in binary.
14+
*
15+
* For a given number N in base-10, return the complement of it's
16+
* binary representation as a base-10 integer.
17+
*/
18+
19+
/**
20+
* @param {number} N
21+
* @return {number}
22+
*/
23+
var bitwiseComplement = function(N) {
24+
return parseInt(N.toString(2).split('').map(n => n ^ 1).join(''), 2);
25+
};

0 commit comments

Comments
 (0)