3370. Smallest Number With All Set Bits
Intuition\n\nGenerate string like below:\n0\n01\n011\n0111\n01111\n011111\n\nConvert to decimal\n0\n1\n3\n7\n15\n31\n\nif greater than n, return that converted 
# Intuition\n```\nGenerate string like below:\n0\n01\n011\n0111\n01111\n011111\n\nConvert to decimal\n0\n1\n3\n7\n15\n31\n\nif greater than n, return that converted decimal number\n```\n\nor\n```\nn   and   next to n   bit and   is 0\n```\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\nvar smallestNumber = function (n) {\n    let binaryString = "0";\n    while (parseInt(binaryString, 2) < n) {\n        binaryString += "1";\n    }\n    return parseInt(binaryString, 2);\n};\n```\n\n```\nvar smallestNumber = function (n) {\n    for (; ; n++) {\n        if ((n & (n + 1)) === 0) {\n            return n\n        }\n    }\n}\n```\n
['JavaScript']