class Solution {
public int hIndex(int[] citations) {
int n = citations.length;
int minn = 0;
int maxx = n;
while (minn < maxx) {
int m = (maxx + minn + 1) / 2;
if (judge(citations, m) >= m) {
minn = m;
} else {
maxx = m - 1;
}
}
return minn;
}
public int judge(int[] citations, int h) {
int ans = 0;
int n = citations.length;
for (int i = 0; i < n; i++) {
if (citations[i] >= h) {
ans++;
}
}
return ans;
}
}