Fastest Solution Java


#1

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

    }
    return -1;
}

}


#2

very good one. O(n) solution