Skip to content

Commit f26337d

Browse files
authored
Merge pull request shubham7668#11 from mrsparkle-70/main
Create concatenated.cpp
2 parents 2ac6f18 + c48d7e3 commit f26337d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

concatenated.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int concatenatedBinary(int n) {
4+
long ans = 0, mod = 1e9+7;
5+
for (int i = 1; i <= n; ++i) {
6+
int len = 0;
7+
for (int j = i; j; j >>= 1, ++len);
8+
ans = ((ans << len) % mod + i) % mod;
9+
}
10+
return ans;
11+
}
12+
};

0 commit comments

Comments
 (0)