forked from DengWangBao/Leetcode-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHIndexII.java
More file actions
27 lines (21 loc) · 735 Bytes
/
HIndexII.java
File metadata and controls
27 lines (21 loc) · 735 Bytes
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
public class HIndexII {
// 1 100
public int hIndex(int[] citations) {
int len = citations.length, left = 0, right = len - 1;
while (left <= right) {
int mid = left + ((right - left) >>> 1);
int articles = len - mid;
if (articles == citations[mid]) {
// 这是临界点,再往下文章数会大于引用
return articles;
} else if (articles > citations[mid]) {
// 文章数大于引用,继续往下走
left = mid + 1;
} else {
// 文章数小于引用,继续往前走
right = mid - 1;
}
}
return len - left;
}
}