int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b; } int specialArray(int* nums, int numsSize){ qsort(nums,numsSize,sizeof(int),cmp); if(nums[numsSize-1]<0) return 0; for(int i=numsSize; i>0; i--){ if(nums[numsSize-i]>=i && (i==numsSize || nums[numsSize-i-1]<i)) return i; } return -1; }