思路
利用Arrays.sort()函数排序,然后从后面开始计算H指数
解题方法
H指数初始化为零,排序后从数组最后一个元素开始,如果当前元素大于等于H指数,则比较前一个元素,并将H指数加1,直到循环结束。
Code
class Solution {
public int hIndex(int[] citations) {
Arrays.sort(citations);
int loc=citations.length-1;
int h=0;
while(loc>=0&&citations[loc]>h){
h++;
loc--;
}
return h;
}
}