Skip to content

Commit 9b85563

Browse files
author
whd
committed
upload
1 parent b9a32f4 commit 9b85563

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

274 H-Index .cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int hIndex(vector<int>& citations) {
4+
sort(begin(citations), end(citations));
5+
int l = 0, r = citations.size();
6+
auto ck = [&] (int x) {
7+
return end(citations) - lower_bound(begin(citations), end(citations), x) >= x;
8+
};
9+
while (l <= r) {
10+
int mid = l + r >> 1;
11+
if (ck(mid)) {
12+
l = mid + 1;
13+
} else {
14+
r = mid - 1;
15+
}
16+
}
17+
return r;
18+
}
19+
};

0 commit comments

Comments
 (0)