LeetCode/com/zerroi/leetcode/ThreeEight/HIndex.java

32 lines
1.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zerroi.leetcode.ThreeEight;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class HIndex {
public static void main(String[] args) {
int[] a = new int[]{3,0,6,1,5};
Solution solution = new Solution();
solution.hIndex(a);
}
}
/*给你一个整数数组 citations ,其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h 指数。
根据维基百科上 h 指数的定义h 代表“高引用次数” ,一名科研人员的 h 指数 是指他(她)至少发表了 h 篇论文,并且 至少 有 h 篇论文被引用次数大于等于 h 。
如果 h 有多种可能的值h 指数 是其中最大的那个。*/
class Solution {
public int hIndex(int[] citations) {
Arrays.sort(citations);
int index = 0;
for (int i = citations.length - 1; i >= 0; i--) {
if (citations[i] > index) {
index++;
}
}
return index;
}
}