You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Given an array of integers in which two elements appear exactly once and all other elements appear exactly twice, find the two elements that appear only once. */
#include <iostream>
#include <vector>
#include <map>
using namespace std;
void findOnceElement(vector<int>& list){
map<int, unsigned int> occurElement ;
int elem ;
map<int, unsigned int>::iterator it;
for (int i=0; i<list.size(); i++){
elem = list[i];
it = occurElement.find(elem);
if (it == occurElement.end()){
occurElement[elem] = 1;
} else{
occurElement.erase(it);
}
}
for (auto rit = occurElement.crbegin(); rit != occurElement.crend(); ++rit){