[Python, Java, C++, Rust] Elegant & Short | O(1) | Power Of Two
Complexity\n- Time complexity: O(1)\n- Space complexity: O(1)\n\n# Code\npython3 []\nclass Solution:\n    def smallestNumber(self, n: int) -> int:\n        retu
# Complexity\n- Time complexity: $$O(1)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```python3 []\nclass Solution:\n    def smallestNumber(self, n: int) -> int:\n        return (1 << n.bit_length()) - 1\n```\n```java []\nimport java.math.BigInteger;\n\nclass Solution {\n    public int smallestNumber(int n) {\n        return (1 << BigInteger.valueOf(n).bitLength()) - 1;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    int smallestNumber(int n) {\n        return (1 << (32 - __builtin_clz(n))) - 1;\n    }\n};\n```\n```Rust []\nimpl Solution {\n    pub fn smallest_number(n: i32) -> i32 {\n        (1 << (32 - n.leading_zeros())) - 1\n    }\n}\n```
['Python', 'C++', 'Java', 'Python3', 'Rust']