Skip to main content

OddOccurrencesInArray

#include <bits/stdc++.h>

using namespace std;

int solution(vector<int> &A)
{
unordered_map<int, int> countMap;
for (auto a : A) ++countMap[a];

for (auto [k, v] : countMap)
{
if (v % 2 == 0) continue;
return k;
}
}

  • T: O(n)O(n)
  • S: O(n)O(n)