Java soln using sort method


#1

public int solve(int[] A) {
int x=-1;
int n=A.length;
Arrays.sort(A);
if(A[n-1]==0){
return 1;
}
for(int i=n-2;i>=0;i–){
if(A[i]==n-i-1 && A[i]!=A[i+1])
{
x=1;
}
}
return x;
}