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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.1MB, accepted 2026-01-01.
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