1711. Count Good Meals

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1711

class Solution:
    def countPairs(self, deliciousness: List[int]) -> int:
        mod = 10**9 + 7
        cnt = Counter(deliciousness)
        res = 0
        for i in range(22):
            s = 1 << i
            for a, m in cnt.items():
                if (b := s - a) in cnt:
                    res += m * (m - 1) if a == b else m * cnt[b]
        return (res >> 1) % mod