Skip to content

Commit 2f38dae

Browse files
author
whd
committed
upload
1 parent 9b85563 commit 2f38dae

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

275 H-Index II .cpp

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

0 commit comments

Comments
 (0)