Leetcode解题报告——274. H-Index

题目要求:
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."

For example, given citations = [3, 0, 6, 1, 5], which 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, his h-index is 3.

题目大意:
给定一个数组代表学者的每篇文章被引用的次数,找出最大的 H-Index。
h-index 定义为:学者有 n 篇文章,其中有 h 篇 的引用次数大于 h

解题思路:
先将数组排序,然后依次遍历:
对于文章 i ,记引用次数大于等于该文章的文章数为 h ,即 h = length - i,如果
citations[i] >= h ,则 h 为 一个H-Index

代码示例:

 public int hIndex(int[] citations) {
       if(citations.length < 1) return 0;
        Arrays.sort(citations);
        int  result = 0;
       for (int i = 0; i < citations.length; i++) {
              if(citations[i] >= citations.length -i  ) 
                    result = Math.max(result,citations.length -i);
        }
        return result;
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,921评论 0 23
  • freqs模拟滤波器的频率响应语法: 描述:freqs 返回一个模拟滤波器的H(jw)的复频域响应(拉普拉斯格式)...
    昔日风阅读 4,366评论 0 0
  • 我很想念你 我很想念你们 我需要你们 他误会我 我渴望脱离他 我想不再和他见面 我情愿拔掉身上所有的刺 情愿溃烂全...
    阿珂你大胆地往前走阅读 278评论 0 0
  • 够好的父母对自己够好, 她对自己温柔体谅, 如同对孩子一样; 够好的父母不为孩子牺牲, 因她知道,能给孩子多少自由...
    烟雨晴子阅读 109评论 0 0
  • 2017年9月13日 星期四 晴转雨 这几天小依芮出牙比较闹腾,晚上都醒好几次,昨天早上实在太困了...
    南海晴芮妈阅读 469评论 0 0