0%

June Leetcoding Challenge(6.18)

LeetCode六月挑战(6.18) H-Index II LeetCode275 解题报告

今天的题很简单哦!

题目描述

Solution
Given an array of citations sorted in ascending order (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.”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Example:

Input: citations = [0,1,3,5,6]
Output: 3
Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had
received 0, 1, 3, 5, 6 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, her h-index is 3.
Note:

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

Follow up:

This is a follow up problem to H-Index, where citations is now guaranteed to be sorted in ascending order.
Could you solve it in logarithmic time complexity?

思路

对与第i篇文章,引用次数是citations[i],那么就有n-i篇文章的引用次数大于等于citations[i]

Java 代码

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public int hIndex(int[] citations) {
int n = citations.length;
for(int i=0;i<n;i++){
int N_h = n-i;
if(citations[i]>=N_h)
return N_h;
}
return 0;
}
}
-------------本文结束感谢您的阅读-------------

本文标题:June Leetcoding Challenge(6.18)

文章作者:Jungle

发布时间:2020年06月18日 - 08:35

最后更新:2020年06月18日 - 07:55

原始链接:http://yoursite.com/2020/06/18/LeetCodeJuneChallenge18th/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Welcome to my other publishing channels