哪个网站可以做社工试题,宣传片企业拍摄公司,wordpress是英文版,基础网站开发274. H 指数
题目描述#xff1a; 给你一个整数数组 citations #xff0c;其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h 指数。
根据维基百科上 h 指数的定义#xff1a;h 代表“高引用次数”#xff0c;一名科研人员的 h指数是指他…274. H 指数
题目描述 给你一个整数数组 citations 其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h 指数。
根据维基百科上 h 指数的定义h 代表“高引用次数”一名科研人员的 h指数是指他她的 n 篇论文中总共有 h 篇论文分别被引用了至少 h 次。且其余的 n - h 篇论文每篇被引用次数 不超过 h 次。
如果 h 有多种可能的值h 指数 是其中最大的那个。
考察重点寻找len(citations) - i篇论文的引用数 ≥ citations[i]i篇论文的引用数 ≤ citations[i]。即我们遍历整个排序后的数组当citations[i] len(citations)-i时说明其为h指数。 golang中的排序封装方法sort.Sort。注意这个函数的输入是封装的数据结构sort.IntSlice,sort.Float64Slice。
func HIndex(citations []int) int {mcitations, mlen : sort.IntSlice(citations), len(citations)sort.Sort(mcitations)if (mlen 1 citations[0] 0) || (mcitations[mlen-1] 0) { //排出[0]和[0,0,0]情况return 0}for i : 0; i mlen; i {oth : mlen - iif oth mcitations[i] { //0,1,3,5,6 遍历到3如果大于3的个数小于mcitations[i]本身则返回个数return oth}}return mlen
}