Skip to content

Commit d2e09f0

Browse files
Create 274. H 指数.md
1 parent 1d19251 commit d2e09f0

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Dichotomy/274. H 指数.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#### 274. H 指数
2+
3+
难度:中等
4+
5+
---
6+
7+
给你一个整数数组 `citations` ,其中 `citations[i]` 表示研究者的第 `i` 篇论文被引用的次数。计算并返回该研究者的 **`h` 指数**
8+
9+
根据维基百科上 [h 指数的定义](https://baike.baidu.com/item/h-index/3991452?fr=aladdin)`h` 代表“高引用次数” ,一名科研人员的 `h` **指数** 是指他(她)至少发表了 `h` 篇论文,并且  **至少**  有 `h` 篇论文被引用次数大于等于 `h` 。如果 `h` 有多种可能的值, **`h` 指数** 是其中最大的那个。
10+
11+
**示例 1:**
12+
13+
```
14+
输入:citations = [3,0,6,1,5]
15+
输出:3
16+
解释:给定数组表示研究者总共有 5 篇论文,每篇论文相应的被引用了 3, 0, 6, 1, 5 次。
17+
  由于研究者有 3 篇论文每篇 至少 被引用了 3 次,其余两篇论文每篇被引用 不多于 3 次,所以她的 h 指数是 3。
18+
```
19+
20+
**示例 2:**
21+
22+
```
23+
输入:citations = [1,3,1]
24+
输出:1
25+
```
26+
27+
**提示:**
28+
29+
* `n == citations.length`
30+
* `1 <= n <= 5000`
31+
* `0 <= citations[i] <= 1000`
32+
33+
---
34+
35+
二分:
36+
37+
显然从 `0` 遍历至 `n` 逐个检查是没问题的,因此二分也适用。
38+
39+
此处需要注意的是 `mid` 值的选取,因为 `left = mid`,当 `left + 1 = right` 时会死循环,所以 `mid = (left + right + 1) / 2`。另外每次检查满足条件的话,则最后结果是大于等于该 `h` 值,否则小于。
40+
41+
```Java
42+
class Solution {
43+
public int hIndex(int[] citations) {
44+
int n = citations.length, left = 0, right = n;
45+
while(left < right){
46+
int mid = (right + left + 1) / 2;
47+
if(check(citations, mid)) left = mid;
48+
else right = mid - 1;
49+
}
50+
return left;
51+
}
52+
53+
private boolean check(int[] citations, int target){
54+
int cnt = 0;
55+
for(int citation: citations){
56+
if(citation >= target) cnt++;
57+
}
58+
return cnt >= target;
59+
}
60+
}
61+
```

0 commit comments

Comments
 (0)