### 题目

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.

According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.”

For example, given citations = [3, 0, 6, 1, 5], which means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, his h-index is 3.

Note: If there are several possible values for h, the maximum one is taken as the h-index.

### 严格按照数学公式，$O(n\log_{}{n})$

  citations
|
0,1,3,5,6
|-len-|



#### 代码

class Solution {
public int hIndex(int[] citations) {
if (citations == null || citations.length == 0) { return 0; }
int len = citations.length;
Arrays.sort(citations);
for (int i = 0; i < len; i++) {
int times = citations[i];
int papers = len - i;
if (times >= (len - i)) { return papers; }
}
return 0;
}
}


### 额外使用一个数组统计文章数，$O(n)$

h-index的意义在于它的数学特性，需要文章的“质量”和“数量”两手都要硬：

1. h-index的第一个上限，是他发过文章的质量（引用）。发100篇引用只有10的文章，h-index也只有10.
2. h-index的第二个上限，是他发文章的稳定性。发了100篇文章，只有1篇10000次引用，其他都是10，h-index也只有10.
3. h-index上升的难度是越来越大的。第1篇文章，只要有1个引用，h-index就上升1。如果h-index要上升到100，就需要他至少有100篇文章的引用数大于等于100。

#### 代码

class Solution {
public int hIndex(int[] citations) {
if (citations == null || citations.length == 0) { return 0; }
int len = citations.length;
int[] freq = new int[len+1];
for (int i = 0; i < len; i++) {
if (citations[i] >= len) {
freq[len]++;
} else {
freq[citations[i]]++;
}
}
int sum = 0;
for (int i = len; i >= 0; i--) {
sum += freq[i];
if (sum >= i) {
return i;
}
}
return 0;
}
}