East and sweet sol in c++


#1

int Solution::solve(vector &A) {
int n = A.size();
sort(A.begin(),A.end());

for(int i=n-2;i>=0;i–)
if( A[i] == n-1-i)
return 1;
return A[n-1]==0 ? 1 : -1;

}


#2

It will not work if the array contains duplicates