[Python3] sum of set bits
Please pull this commit for solutions of weekly 303. \n\nThe key info of this problem is that the sum of set bits of x or y and x and y is the the sum of set bi
Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/d61cd3ed09bbf59fd619802a6e861a516ec17094) for solutions of weekly 303. \n\nThe key info of this problem is that the sum of set bits of `x or y` and `x and y` is the the sum of set bits of `x` and `y`. With that this can be solved efficiently via freq array and prefix sum array. \n\n```\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        nums = set(nums)\n        freq = [0]*30\n        for x in nums: freq[bin(x).count(\'1\')] += 1\n        prefix = list(accumulate(freq, initial=0))\n        ans = 0 \n        for x in nums: \n            bits = bin(x).count(\'1\')\n            lo = min(30, max(0, k-bits))\n            ans += prefix[-1] - prefix[lo]\n        return ans \n```\n\nBased on @lee215\n```\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        freq = Counter(map(int.bit_count, set(nums)))\n        return sum(v1*v2 for k1, v1 in freq.items() for k2, v2 in freq.items() if k1+k2 >= k)\n```
['Python3']