Skip to content

Latest commit

 

History

History
24 lines (15 loc) · 443 Bytes

762.md

File metadata and controls

24 lines (15 loc) · 443 Bytes

Prime Number of Set Bits in Binary Representation

Description

link


Solution

  • bin in python

Code

O(n)

class Solution:
    def countPrimeSetBits(self, L: int, R: int) -> int:
        primes = {2, 3, 5, 7, 11, 13, 17, 19}
        return sum(map(lambda x: bin(x).count('1') in primes, range(L, R+1)))