File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments