Like in the title. I have this function that returns a number which occured odd times in the array. And I need to make it at least 0.28s faster :) . What can i do to improve this programme?
int OddOccurencesInArray(vector<int> &A) {
map<int, size_t> mapa;
for (int& i : A){
mapa[i]++;
}
for (auto& p : mapa){
if(p.second % 2 == 1){
return p.first;
}
}
return -1;
}
Aucun commentaire:
Enregistrer un commentaire