2354. Number of Excellent Pairs

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2354

class Solution:
    def countExcellentPairs(self, nums: List[int], k: int) -> int:
        s = set(nums)
        res = 0
        cnt = Counter()
        for v in s:
            cnt[v.bit_count()] += 1
        for v in s:
            t = v.bit_count()
            for i, x in cnt.items():
                if t + i >= k:
                    res += x
        return res