954. Array of Doubled Pairs

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

Содержание

LeetCode problem 954

class Solution:
    def canReorderDoubled(self, arr: List[int]) -> bool:
        freq = Counter(arr)
        if freq[0] & 1:
            return False
        for x in sorted(freq, key=abs):
            if freq[x << 1] < freq[x]:
                return False
            freq[x << 1] -= freq[x]
        return True