1 给出一个 Java 题目
Given an array of citations (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."
Example:
Input: citations = [3,0,6,1,5]
Output: 3
Explanation:
* [3,0,6,1,5] means the researcher has 5 papers in total and each
of them had received 3, 0, 6, 1, 5 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.
2 解决思路、编写 Java 代码、执行
思路:先把数组从大到小排序,再从头遍历,找到符合要求的 h-index 值。
[3,0,6,1,5][6,5,3,1,0]
遍历时,如果数组中该位置的数值大于等于其序号+1,则 h-index 至少为序号+1。
例如:
第 0 位为 6,6>=1,则 h-index=1;
第 1 位为 5,5>=2,则 h-index=2;
第 2 位为 3,3>=3,则 h-index=3;
第 3 位为 1,1<4,则 h-index 不再变化,算法终止。
在 Eclipse 中构造工程,命名为 SC2020Spring_Classroom_Exercise;
在 src 中创建包,命名为 exercise_6_6;
在包中创建类 HIndex.java。
(1) 从控制台读入用户输入,按 3,0,6,1,5 的格式,存储于数组