Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- int solution(vector<int> &A) {
- // write your code in C++11 (g++ 4.8.2)
- std::sort(A.begin(), A.end());
- if(A.size() <= 2 || A[0] != A[1])
- return A.front();
- for(auto it = A.begin() + 2; it < A.end()-2; it += 2)
- {
- if(*it != *(it+1))
- {
- if(*(it+1) != *(it+2))
- return *++it;
- return *it;
- }
- }
- return A.back();
- }
Advertisement
Add Comment
Please, Sign In to add comment