File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,469 LeetCode solutions in JavaScript
1
+ # 1,470 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1294
1294
1675|[ Minimize Deviation in Array] ( ./solutions/1675-minimize-deviation-in-array.js ) |Hard|
1295
1295
1678|[ Goal Parser Interpretation] ( ./solutions/1678-goal-parser-interpretation.js ) |Easy|
1296
1296
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|
1297
1298
1716|[ Calculate Money in Leetcode Bank] ( ./solutions/1716-calculate-money-in-leetcode-bank.js ) |Easy|
1298
1299
1718|[ Construct the Lexicographically Largest Valid Sequence] ( ./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js ) |Medium|
1299
1300
1726|[ Tuple with Same Product] ( ./solutions/1726-tuple-with-same-product.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments