Skip to content

Commit 9638b9a

Browse files
authored
Create 1680-concatenation-of-consecutive-binary-numbers.js
1 parent 9c3408e commit 9638b9a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
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 concatenatedBinary = function(n) {
6+
let res = ''
7+
const mod = 10 ** 9 + 7
8+
for(let i = 1; i <= n; i++) {
9+
res += dec2bin(i)
10+
res = dec2bin(parseInt(res, 2) % mod)
11+
}
12+
return parseInt(res, 2) % mod
13+
};
14+
function dec2bin(dec){
15+
return (dec >>> 0).toString(2);
16+
}

0 commit comments

Comments
 (0)