-
Notifications
You must be signed in to change notification settings - Fork 0
/
H-Index II.cpp
30 lines (21 loc) · 939 Bytes
/
H-Index II.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
class Solution {
public:
int hIndex(vector<int>& vec) {
int n = vec.size();
int l = 0, r = n-1;
while(l <= r) {
int mid = l + (r-l)/2;
if(vec[mid] >= n-mid) {
r = mid-1;
} else {
l = mid+1;
}
}
return n - l;
}
};
// LEETCODE 275
// Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in an ascending order, return compute the researcher's h-index.
// According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.
// If there are several possible values for h, the maximum one is taken as the h-index.
// You must write an algorithm that runs in logarithmic time.