My easy to understand c++ solution


#1

int Solution::solve(vector &a) {
int n=a.size();
sort(a.begin(),a.end());
if(a[n-1]==0)return 1;
for(int i=0;i<n;i++){
int j=n-i-1;
if(a[i]!=a[i+1]){
if(a[i]==j)return 1;
}
}
return -1;
}