Skip to content
LC-3370 Easy LeetCode

3370. Smallest Number With All Set Bits

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 76% Topics: Math, Bit Manipulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(1)
# Space: O(1)

# bit manipulation
class Solution(object):
    def smallestNumber(self, n):
        """
        :type n: int
        :rtype: int
        """
        return (1<<n.bit_length())-1

Solution from kamyu104/LeetCode-Solutions · MIT