Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 54b1e0f

Browse filesBrowse files
authored
Create 27 concatConsecutiveNos.cpp
1 parent 8b85124 commit 54b1e0f
Copy full SHA for 54b1e0f

File tree

Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int concatenatedBinary(int n) {
4+
5+
long res = 0, mod = 1e9+7, len_of_curr = 0;
6+
for (int i = 1; i <= n; i++) {
7+
8+
// the len increases every time we reach a number which is a power of two.
9+
if ((i & (i-1)) == 0)
10+
len_of_curr++;
11+
12+
res = (res << len_of_curr) % mod;
13+
res += i % mod;
14+
}
15+
return res;
16+
17+
}
18+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.