-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2007.cpp
More file actions
24 lines (24 loc) · 749 Bytes
/
2007.cpp
File metadata and controls
24 lines (24 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
vector<int> findOriginalArray(vector<int>& changed) {
map<int, int> mp;
vector<int> res;
for (auto& num : changed) mp[num]++;
for (auto& element : mp) {
int current = element.first;
int doubleCurrent = current * 2;
int count = element.second;
if (current == 0) {
if (count & 1) return {};
count /= 2;
}
if (count > 0) {
if (mp[doubleCurrent] < count) return {};
for (int i = 0; i < count; ++i) res.push_back(current);
mp[doubleCurrent] -= count;
mp[current] -= count;
}
}
return res;
}
};