Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://leetcode.com/explore/challenge/card/january-leetcoding-challenge-2021/582/week-4-january-22nd-january-28th/3618/
- class Solution {
- public:
- int concatenatedBinary(int n) {
- const int mod = 1e9 + 7;
- long result = 0;
- int length = 0;
- for(int i = 1; i <= n; ++i) {
- if((i & (i-1)) == 0) {
- length++;
- }
- result = ((result << length) | i) % mod;
- }
- return result;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement