Simple C++ solution with unordered_map


#1
int Solution::solve(vector<int> &A) {
    unordered_map<int,int> m;
    for(auto x:A) m[x]=0;
    sort(A.begin(),A.end());

    for(int i=0;i<A.size()-1;i++)
        if(A[i]!=A[i+1])
            m[A[i]]=A.size()-i-1;
    for(auto x:m)
        if(x.first==x.second) return 1;
    return -1;
}