---
# System prepended metadata

title: 0274. H-Index
tags: [Leetcode, FaceBook, Bucket Sort, Medium]

---

# 0274. H-Index
###### tags: `Leetcode` `Medium` `FaceBook` `Bucket Sort`
Link: https://leetcode.com/problems/h-index/
## 思路 $O(N)$ $O(N)$
要找一个数，使得引用数大于等于a的论文数大于等于a
按论文的引用数做bucket sort
bucket sort的array的大小是citations的length
因为bucket的index就是可能的返回值也就是a，的取值范围就是[0, citations.length]

## Code
```java=
class Solution {
    public int hIndex(int[] citations) {
        int[] buckets = new int[citations.length+1];
        int len = citations.length;
        for(int c:citations){
            buckets[Math.min(len,c)]++;
        }
        int i = len;
        for(int count = buckets[len];i>count;count+=buckets[i]){
            i--;
        }
        return i;
    }
}
```