[Python] clean solution using lowbit - O(N) / O(1)
Idea\n\nWe simply go through every number from 1 to n  and update ans. The idea is somewhat similar to rolling hash.\n\nIn Python, bin() comes in handy. The bin
**Idea**\n\nWe simply go through every number from `1` to `n`  and update `ans`. The idea is somewhat similar to rolling hash.\n\nIn Python, `bin()` comes in handy. The `bin()` method converts and returns the binary equivalent string of a given integer. For example, `bin(3)` returns `0b11`.\n\nIf we are not using `bin()`, we can update the length of the binary representation, `l`, whenever we see `x & -x == x`. The idea of `x & -x` comes from Fenwick Tree, which gives us the low bit of `x`. And this condition checks if `x` is something like `100...0`.\n\n</br>\n\n**Complexity**\n\n- Time complexity: `O(N)`\n- Space complexity: `O(1)`\n\n</br>\n\n**Python**\n\nusing lowbit (`x & -x`):\n\n```Python\nclass Solution:\n    def concatenatedBinary(self, n: int) -> int:\n        ans, l, MOD = 0, 0, 10 ** 9 + 7\n        for x in range(1, n + 1):\n            if x & (-x) == x: l += 1\n            ans = (ans * (1 << l) + x) % MOD\n        return ans \n```\n\nusing `bin()`:\n\n\n```Python\nclass Solution:\n    def concatenatedBinary(self, n: int) -> int:\n        ans, MOD = 0, 10 ** 9 + 7\n        for x in range(1, n + 1):\n            ans = (ans * (1 << (len(bin(x)) - 2)) + x) % MOD\n        return ans \n```\n
[]