java 275. H-Index II(#)。java

Posted

tags:

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

public int hIndex(int[] citations) {
	int len = citations.length;
	int lo = 0, hi = len - 1;
	while (lo <= hi) {
		int med = (hi + lo) / 2;
		if (citations[med] == len - med) {
			return len - med;
		} else if (citations[med] < len - med) {
			lo = med + 1;
		} else { 
			//(citations[med] > len-med), med qualified as a hIndex,
		    // but we have to continue to search for a higher one.
			hi = med - 1;
		}
	}
	return len - lo;
}
public class Solution {
    public int hIndex(int[] citations) {
        if (citations == null || citations.length < 1) return 0;
        int i = 0;
        int len = citations.length;
        while (i < len && citations[len - 1 - i] > i) {
            i++;
        }
        return i;
    }
}

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

java 275. H-Index II(#)。java

java 275. H-Index II(#)。java

java 275. H-Index II(#)。java

java 275. H-Index II(#)。java

[LeetCode] 275. H-Index II H指数 II

275. H-Index II