Skip to content

Commit a1b67b4

Browse files
committed
Create 1680. 连接连续二进制数字.js
1 parent 88f7ddf commit a1b67b4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

1680. 连接连续二进制数字.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var concatenatedBinary = function (n) {
6+
const MOD = BigInt(10 ** 9 + 7);
7+
let result = 0n;
8+
for (let i = 1n; i <= n; i++) {
9+
const binStr = i.toString(2);
10+
result = ((result << BigInt(binStr.length)) + i) % MOD;
11+
}
12+
return result;
13+
};

0 commit comments

Comments
 (0)