Skip to content

Commit 23f4c26

Browse files
authored
Create 1012-complement-of-base-10-integer.js
1 parent 1c44b97 commit 23f4c26

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

1012-complement-of-base-10-integer.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number} N
3+
* @return {number}
4+
*/
5+
const bitwiseComplement = function(N) {
6+
let binStr = bin(N)
7+
let str = ''
8+
for(let i = 0; i < binStr.length; i++) {
9+
str += binStr[i] === '0' ? '1' : '0'
10+
}
11+
return parseInt(str, 2)
12+
};
13+
14+
function bin(N) {
15+
return (N >>> 0).toString(2)
16+
}

0 commit comments

Comments
 (0)