zoukankan      html  css  js  c++  java
  • H-Index

    package cn.edu.xidian.sselab.hashtable;

    /**
     *
     * @author zhiyong wang
     * title: H-Index
     * content:
     *  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.
     *
     *Note: If there are several possible values for h, the maximum one is taken as the h-index.
     *
     */
    public class HIndex {

        //这道题,自己理解错了题意,正确的理解方式是:论文被引用次数大于或者等于h次,这样的论文数量也要大于或者等于h,此时的h才是H
        //注:h的取值返回是[0,论文的总篇数]
        //首先是建立一个数组,用于将论文的引用次数从小到大进行排序,当然引用次数大于总论文个数的都放在数组的最后一位
        //然后从数组最后一个开始,计算论文的个数是否大于或者等于论文引用的次数
        public int hIndex(int[] citations){
            int length = citations.length;
            int result = 0;
            if(length == 0) return 0;
            int[] index = new int[length+1];
            for(int i=0;i<length;i++){
                if(citations[i]>length){
                    index[length]++;
                }else{
                    index[citations[i]]++;
                }
            }
            for(int i=length;i>=0;i--){
                if(result >= i) return i;
                result +=index[i];
            }
            return 0;
        }
    }

  • 相关阅读:
    log4net封装类
    (转)MySQL InnoDB 架构
    备份宽带不足,innobackupex备份导致从库不可写
    从库查询阻塞xtrabackup备份,应该是kill备份还是kill查询的问题
    rabbitmq群集安装
    MySQL索引选择问题(要相信MySQL自己选择索引的能力)
    binlog_format产生的延迟问题
    命令行登录mysql报Segmentation fault故障解决
    MySQL5.7.21启动异常的修复
    大查询对mha切换的影响
  • 原文地址:https://www.cnblogs.com/wzyxidian/p/5171247.html
Copyright © 2011-2022 走看看