[Python] Oneliner explained
What we actually need to find in this problem is length of our number in bits: if we have 10 = 1010, then complementary is 5 = 101. Note, that 5 + 10 = 15 = 2^4
What we actually need to find in this problem is length of our number in bits: if we have `10 = 1010`, then complementary is `5 = 101`. Note, that `5 + 10 = 15 = 2^4 - 1`. So, let us just find length of our number in bits and subtract `N-1`.\n\n**Complexity** time complexity is `O(log N)` to find its length; space complexity is also `O(log N)` to keep binary representation of our number.\n\n```\nclass Solution:\n    def bitwiseComplement(self, N):\n         return (1<<(len(bin(N)) - 2)) - 1 - N\n```\n\nIf you have any questions, feel free to ask. If you like solution and explanations, please **Upvote!**
[]