fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int singleNumber(vector<int>& nums) {
  5. map<int,int> mp;
  6. for(auto x:nums){
  7. mp[x]++;
  8. }
  9. for(auto x:nums){
  10. if(mp[x]==1)
  11. return x;
  12. }
  13. return -1;
  14. }
  15.  
  16. int main() {
  17. int T;
  18. cin>>T;
  19. vector<int> v;
  20. for(int i=0;i<T;i++){
  21. int temp;
  22. cin>>temp;
  23. v.push_back(temp);
  24. }
  25. cout<<singleNumber(v)<<endl;
  26. return 0;
  27. }
Success #stdin #stdout 0s 5536KB
stdin
3
1
8
1
stdout
8