[Swift, C++, Python3] Simplest solution 0ms O(logN)
Intuition\nThe first numbers which contain only set bits are 1, 3, 7, 15, 31.\nSo, each next only set bits number can be calculated as current * 2 + 1.\n\n\n\n\
# Intuition\nThe first numbers which contain only set bits are 1, 3, 7, 15, 31.\nSo, each next only set bits number can be calculated as `current * 2 + 1`.\n\n![Screenshot 2024-12-02 095847.png](https://assets.leetcode.com/users/images/3a9b413f-1b8b-46f0-bc1f-692d6818ed88_1733122778.0951207.png)\n\n\n# Approach\nWe can start from 1 and calculate next number while our number lesser than n.\n\n# Complexity\n- Time complexity:\nO(logN)\n\n- Space complexity:\nO(1)\n\n![0ms.png](https://assets.leetcode.com/users/images/fe25f967-e3a9-405d-b7c2-d86fef07d60d_1733115874.7205248.png)\n\n# Swift Code\n```swift []\nclass Solution {\n    func smallestNumber(_ n: Int) -> Int {\n        var curr = 1\n        while curr < n {\n            curr = curr * 2 + 1\n        }\n        return curr\n    }\n}\n```\n\n# C++ Code\n```cpp []\nclass Solution {\npublic:\n    int smallestNumber(int n) {\n        int curr = 1;\n        while (curr < n)\n            curr = curr * 2 + 1;\n        return curr;\n    }\n};\n```\n\n# Python3 Code\n```python3 []\nclass Solution:\n    def smallestNumber(self, n: int) -> int:\n        curr = 1\n        while curr < n:\n            curr = curr * 2 + 1\n        return curr\n```\n
['Swift', 'C++', 'Python3']