LeetCode solutions

3676. Smallest Number With All Set Bits

My accepted Python solution to LeetCode problem 3676, Smallest Number With All Set Bits, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.1MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.1MB, accepted 2026-01-01.

python
class Solution:
    def smallestNumber(self, n: int) -> int:
        # Find smallest number of form 2^k - 1 that is >= n
        result = 1
        while result < n:
            result = result * 2 + 1
        return result

Source