2007. Find Original Array From Doubled Array
On This Page
class Solution:
def findOriginalArray(self, changed: List[int]) -> List[int]:
n = len(changed)
if n & 1:
return []
cnt = Counter(changed)
changed.sort()
res = []
for x in changed:
if cnt[x] == 0:
continue
if cnt[x * 2] <= 0:
return []
res.append(x)
cnt[x] -= 1
cnt[x * 2] -= 1
return res if len(res) == n // 2 else []