Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 94ad215

Browse files
committed
Add solution #1680
1 parent a068076 commit 94ad215

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,469 LeetCode solutions in JavaScript
1+
# 1,470 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1294,6 +1294,7 @@
12941294
1675|[Minimize Deviation in Array](./solutions/1675-minimize-deviation-in-array.js)|Hard|
12951295
1678|[Goal Parser Interpretation](./solutions/1678-goal-parser-interpretation.js)|Easy|
12961296
1679|[Max Number of K-Sum Pairs](./solutions/1679-max-number-of-k-sum-pairs.js)|Medium|
1297+
1680|[Concatenation of Consecutive Binary Numbers](./solutions/1680-concatenation-of-consecutive-binary-numbers.js)|Medium|
12971298
1716|[Calculate Money in Leetcode Bank](./solutions/1716-calculate-money-in-leetcode-bank.js)|Easy|
12981299
1718|[Construct the Lexicographically Largest Valid Sequence](./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js)|Medium|
12991300
1726|[Tuple with Same Product](./solutions/1726-tuple-with-same-product.js)|Medium|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1680. Concatenation of Consecutive Binary Numbers
3+
* https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/
4+
* Difficulty: Medium
5+
*
6+
* Given an integer n, return the decimal value of the binary string formed by concatenating the
7+
* binary representations of 1 to n in order, modulo 109 + 7.
8+
*/
9+
10+
/**
11+
* @param {number} n
12+
* @return {number}
13+
*/
14+
var concatenatedBinary = function(n) {
15+
const MOD = 1e9 + 7;
16+
let result = 0;
17+
18+
for (let i = 1; i <= n; i++) {
19+
const bitLength = Math.floor(Math.log2(i)) + 1;
20+
result = ((result * (1 << bitLength)) % MOD + i) % MOD;
21+
}
22+
23+
return result;
24+
};

0 commit comments

Comments
 (0)