JAVA练习364- H 指数
题目概览给你一个整数数组citations其中citations[i]表示研究者的第i篇论文被引用的次数。计算并返回该研究者的h指数。根据维基百科上 h 指数的定义h代表“高引用次数” 一名科研人员的h指数是指他她至少发表了h篇论文并且至少有h篇论文被引用次数大于等于h。如果h有多种可能的值h指数是其中最大的那个。示例 1输入citations [3,0,6,1,5]输出3解释给定数组表示研究者总共有 5 篇论文每篇论文相应的被引用了 3, 0, 6, 1, 5次。由于研究者有 3 篇论文每篇至少被引用了 3次其余两篇论文每篇被引用不多于3次所以她的h指数是 3。示例 2输入citations [1,3,1]输出1提示n citations.length1 n 50000 citations[i] 1000来源274. H 指数 - 力扣LeetCode解题分析方法计数大于 n 的数可以当做 n 来算不影响结果因此我们可以用一个长度为 n 的数组 count 来记录 每个引用次数 的出现个数然后从 i n 开始遍历每次遍历累加上 count [ i ]当累加和 i 时说明至少有 i 个引用次数大于 i 的返回 i。时间复杂度O(n)空间复杂度O(n)class Solution { public int hIndex(int[] citations) { int n citations.length; int[] count new int[n1]; for (int citation: citations) { count[Math.min(citation, n)]; } int res 0; for (int i n; i 0; i--) { res count[i]; if (res i) { return i; } } return 0; } }