<jupyter_start><jupyter_text>说明：    给定具有偶数长度的整数A的数组，当且仅当有可能重新排序以使        A [2 * i + 1] = 2 * A [2 * i] 当 0 <= i < len（A ）/ 2。要求：重新排序，idx是奇数的位置是idx是偶数位置的二倍。Example 1:    Input: [3,1,3,6]    Output: falseExample 2:    Input: [2,1,2,6]    Output: falseExample 3:    Input: [4,-2,2,-4]    Output: true    Explanation: We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4].Example 4:    Input: [1,2,4,16,8,4]    Output: falseNote:    1、0 <= A.length <= 30000    2、A.length is even    3、-100000 <= A[i] <= 100000<jupyter_code># i 可能的取值：0、2、4、6、len(A)
from collections import Counter

class Solution:
    def canReorderDoubled(self, A):
        if not A: return True
        a_freq = Counter(A)
        seen = set()
        for a in A:
            if a in seen: continue
            if a_freq[a] == 0: 
                seen.add(a)
                continue
            if a_freq[a * 2] >= a_freq[a] and a * 2 not in seen:
                a_freq[a * 2] -= a_freq[a]
            elif a % 2 == 0 and a_freq[a // 2] >= a_freq[a]  and a // 2 not in seen:
                a_freq[a // 2] -= a_freq[a]
            else:
                return False
        return True
from collections import Counter

class Solution:
    def canReorderDoubled(self, A):
        if not A: return True
        a_freq = Counter(A)
        
        for a in sorted(a_freq.keys(), key=abs):
            if a_freq[a] == 0: 
                continue
            if a == 0 and a_freq[0] % 2 == 0:
                a_freq[0] = 0
                continue
            if a_freq[a * 2] > 0:
                min_val = min(a_freq[a * 2], a_freq[a])
                a_freq[a * 2] -= min_val
                a_freq[a] -= min_val
        return all(not v for v in a_freq.values())
solution = Solution()
solution.canReorderDoubled([-6,2,-6,4,-3,8,3,2,-2,6,1,-3,-4,-4,-8,4])
from collections import Counter

class Solution:
    def canReorderDoubled(self, A):
        a_freq = Counter(A)
        for n in sorted(a_freq.keys(), key=abs):
            double = 2 * n
            while a_freq[n] > 0  and a_freq[double] > 0:
                double = 2 * n
                a_freq[n] -= 1
                a_freq[double] -= 1
        return all(not v for v in a_freq.values())
solution = Solution()
solution.canReorderDoubled([-6,2,-6,4,-3,8,3,2,-2,6,1,-3,-4,-4,-8,4])
if 0:
    print(2)
class Solution:
    def canReorderDoubled(self, A: List[int]) -> bool:
        c = Counter(A)
        for n in sorted(c.keys(), key=abs):
            while c[n] > 0 and c[(double := 2 * n)] > 0:
                c[n] -= 1
                c[double] -= 1
        return all(not v for v in c.values())
from collections import Counter

class Solution:
    def canReorderDoubled(self, A):
        if not A: return True
        a_freq = Counter(A)
        
        for a in sorted(a_freq.keys(), key=abs):
            if a_freq[a] == 0: 
                continue
            if a == 0 and a_freq[0] % 2 == 0:
                a_freq[0] = 0
                continue
            if a_freq[a * 2] > 0:
                min_val = min(a_freq[a * 2], a_freq[a])
                a_freq[a * 2] -= min_val
                a_freq[a] -= min_val
        return all(not v for v in a_freq.values())
solution = Solution()
solution.canReorderDoubled([-6,2,-6,4,-3,8,3,2,-2,6,1,-3,-4,-4,-8,4])<jupyter_output>1
2
-2
-3
3
4
-4
-6
6
8
-8
{'fraction_non_alphanumeric': 0.14430229098482594, 'fraction_numerical': 0.05028265397203213, 'mean_word_length': 1.702572347266881, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '8361', 'license': 'Apache-2.0', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1271, 'n_words': 331, 'path': 'Array/0925/954. Array of Doubled Pairs.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '3361'}