-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
34 lines (31 loc) · 791 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution {
public:
int hIndex(vector<int>& citations) {
auto check = [&](int h) -> bool {
int cnt = 0;
for (int v : citations) cnt += v >= h;
return cnt >= h;
};
int l = 0, r = citations.size();
while (l <= r) {
int m = l + (r - l) / 2;
if (check(m)) {
l = m + 1;
} else {
r = m - 1;
}
}
return r;
}
};
class Solution {
public:
int hIndex(vector<int>& citations) {
int n = citations.size();
sort(citations.begin(), citations.end());
for (int i = n - 1; i >= 0; --i) {
if (citations[i] < n - i) return n - i - 1;
}
return citations.size();
}
};