Binary Manipulation Approach || Python3
Binary Manipulation Approach:\n\n# Intuition\n- The idea is to find the smallest number that has the same number of bits set to 1 as the binary representation o
# Binary Manipulation Approach:\n\n# Intuition\n- The idea is to find the smallest number that has the same number of bits set to 1 as the binary representation of the given number \\( n \\).\n\n# Approach\n- Convert \\( n \\) to its binary representation.\n- Count the number of bits set to 1.\n- Construct a binary number composed entirely of 1s with the same length.\n- Convert the binary string back to an integer and return it.\n\n# Complexity\n- Time complexity: $$O(\\log n)$$\n- Space complexity: $$O(\\log n)$$\n\n# Code\n```python\nclass Solution:\n    def smallestNumber(self, n: int) -> int:\n        l = bin(n)[2:]               # Convert n to binary and strip the "0b" prefix.\n        l = \'1\' * len(l)             # Create a binary string of 1s with the same length.\n        return int(l, 2)             # Convert the binary string back to an integer.\n
['Python3']