2308. Divide Array Into Equal Pairs
My accepted C++ solution to LeetCode problem 2308, Divide Array Into Equal Pairs, running in 3ms.
- Difficulty: Easy
- C++
- Runtime 3ms
- Memory 18.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 3ms, memory 18.3MB, accepted 2025-12-27.
class Solution {
public:
bool divideArray(vector<int>& nums) {
unordered_map<int, int> cnt;
for (int n : nums) cnt[n]++;
for (auto& p : cnt) if (p.second % 2) return false;
return true;
}
};