1
class Solution {
2
public int specialArray(int[] nums) {
3
int x = nums.length;
4
int[] counts = new int[x + 1];
5

6
for (int elem : nums)
7
if (elem >= x) counts[x]++;
8
else counts[elem]++;
9

10
int res = 0;
11
for (int i = counts.length - 1; i > 0; i--) {
12
res += counts[i];
13
if (res == i) return i;
14
}
15

16
return -1;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0