java 274. H-Index(#)。java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 274. H-Index(#)。java相关的知识,希望对你有一定的参考价值。

public class Solution {
    public int hIndex(int[] citations) {
        // sorting the citations in ascending order
        Arrays.sort(citations);
        // finding h-index by linear search
        int i = 0;
        while (i < citations.length && citations[citations.length - 1 - i] > i) {
            i++;
        }
        return i; // after the while loop, i = i' + 1
    }
}
public class Solution {
    public int hIndex(int[] citations) {
        int n = citations.length;
        int[] papers = new int[n + 1];
        // counting papers for each citation number
        for (int c: citations)
            papers[Math.min(n, c)]++;
        // finding the h-index
        int k = n;
        for (int s = papers[n]; k > s; s += papers[k])
            k--;
        return k;
    }
}
public class Solution {
    public int hIndex(int[] citations) {
        if (citations == null || citations.length < 1) return 0;
        Arrays.sort(citations);
        int res = 0;
        int len = citations.length;
        for (int i = len - 1; i >= 0; i--) {
            if (citations[i] > res) {
                res++;
            }
        }
        return res;
    }
}

以上是关于java 274. H-Index(#)。java的主要内容,如果未能解决你的问题,请参考以下文章

java 274. H-Index(#)。java

java 274. H-Index(#)。java

java 274. H-Index(#)。java

java 274. H-Index(#)。java

[LeetCode] 274. H-Index Java

(Java) LeetCode 274. H-Index —— H指数