We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intlonelyinteger(vector<int>a){// Use a set to track numbers we've encountered as we iterate throughset<int>b;for(inti:a){// If we lookup i and it doesn't return the end iteratorif(b.find(i)!=b.end()){b.erase(i);// Remove the already encountered integer}else{b.emplace(i);// Track encountered integer}}// Convert set to vectorvector<int>b_vect(b.begin(),b.end());// There should only be one element left...returnb_vect.at(0);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
C++ deserves more love :(