Python3 || 1 line, Count the bits  || T/S: 99% / 59%
This problem is equivalent to: Given a number n, find the greatest integer with the same bit-length. Thus, we determine the bit-length of n and use mathematics 
This problem is equivalent to: *Given a number *n*, find the greatest integer with the same bit-length.* Thus, we determine the bit-length of *n* and use mathematics to complete the task.\n\n```python3 []\nclass Solution:\n    def smallestNumber(self, n: int) -> int:\n        \n        return pow(2, n.bit_length()) - 1\n```\n```cpp []\nclass Solution {\npublic:\n    int smallestNumber(int n) {\n        return (1 << (32 - __builtin_clz(n))) - 1;\n    }\n};\n```\n```java []\nclass Solution {\n\n    public int smallestNumber(int n) {\n        return (1 << (Integer.SIZE - Integer.\n        \n        numberOfLeadingZeros(n))) - 1; }\n}\n\n```\nI could be wrong, but I think that time complexity is *O*(log log *N*) and space complexity is *O*(1), *N* ~ `n`.\n\n[https://leetcode.com/problems/smallest-number-with-all-set-bits/submissions/1473080933/](https://leetcode.com/problems/smallest-number-with-all-set-bits/submissions/1473080933/)
['C++', 'Java', 'Python3']