donarturo1991

firstUnique

Jul 28th, 2021 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1.  
  2. #include<vector>
  3. #include<map>
  4.  
  5. int solution(vector<int> &A) {
  6.     // write your code in C++14 (g++ 6.2.0)
  7.     using namespace std;
  8.    
  9.     vector<int> Vaux;
  10.     map<int, int> M;
  11.     int result=-1;
  12.    
  13.  
  14.     for (int it : A){
  15.         if (M.count(it)!=0) M[it]+=1;
  16.         else if (M.count(it)==0) {
  17.             M[it]=1;
  18.             Vaux.push_back(it);
  19.         }
  20.     }
  21.  
  22.     for (int it : Vaux){
  23.         if (M[it]==1) {
  24.             result=it;
  25.             break;
  26.         }
  27.  
  28.     }
  29.    
  30.     return result;
  31.  
  32. }
Add Comment
Please, Sign In to add comment