#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int lonelyinteger(const std::vector<int>& a)
{
typedef std::map<int, int> IntMap;
IntMap theMap;
// build the map
for_each(a.begin(), a.end(), [&](int n){ theMap[n]++; });
// find the first entry with a count of 1
return
find_if(theMap.begin(), theMap.end(),
[](const IntMap::value_type& pr){return pr.second == 1; })->first;
}
int main()
{
std::vector<int> TestVect = { 1, 1, 2 };
cout << lonelyinteger(TestVect);
}
I2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBsb25lbHlpbnRlZ2VyKGNvbnN0IHN0ZDo6dmVjdG9yPGludD4mIGEpIAp7CiAgICB0eXBlZGVmIHN0ZDo6bWFwPGludCwgaW50PiBJbnRNYXA7CiAgICBJbnRNYXAgdGhlTWFwOyAgCgogICAgLy8gYnVpbGQgdGhlIG1hcAogICAgZm9yX2VhY2goYS5iZWdpbigpLCBhLmVuZCgpLCBbJl0oaW50IG4peyB0aGVNYXBbbl0rKzsgfSk7CgogICAgLy8gZmluZCB0aGUgZmlyc3QgZW50cnkgd2l0aCBhIGNvdW50IG9mIDEKICAgIHJldHVybiAKICAgICAgIGZpbmRfaWYodGhlTWFwLmJlZ2luKCksIHRoZU1hcC5lbmQoKSwKICAgICAgIFtdKGNvbnN0IEludE1hcDo6dmFsdWVfdHlwZSYgcHIpe3JldHVybiBwci5zZWNvbmQgPT0gMTsgfSktPmZpcnN0Owp9CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6dmVjdG9yPGludD4gVGVzdFZlY3QgPSB7IDEsIDEsIDIgfTsKICAgIGNvdXQgPDwgbG9uZWx5aW50ZWdlcihUZXN0VmVjdCk7Cn0=