Skip to content

Commit 302c1ea

Browse files
authored
Create divide-array-into-equal-pairs.cpp
1 parent dda904f commit 302c1ea

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

C++/divide-array-into-equal-pairs.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
// freq table
5+
class Solution {
6+
public:
7+
bool divideArray(vector<int>& nums) {
8+
unordered_map<int, int> odd;
9+
for (const auto& x : nums) {
10+
odd[x] = (odd[x] + 1) % 2;
11+
}
12+
return all_of(cbegin(odd), cend(odd), [](const auto& x) {
13+
return x.second == 0;
14+
});
15+
}
16+
};

0 commit comments

Comments
 (0)