My simple c++ solution.Any suggestions?


#1

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


#2

Care to explain this code?