Leetcode 991 Solution
This article provides solution to leetcode question 991 (array-of-doubled-pairs)
Access this page by simply typing in "lcs 991" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/array-of-doubled-pairs
Solution
class Solution {
public:
bool canReorderDoubled(vector<int>& A) {
map<int, int> m;
for (auto a: A)
m[abs(a)]++;
for (auto it = m.begin(); it != m.end(); it++)
{
while (it->second)
{
it->second--;
if (m[2 * it->first] == 0)
return false;
m[2 * it->first]--;
}
}
return true;
}
};