数组|274. H 指数

274. H 指数

**题目:**给你一个整数数组 citations ,其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h 指数。根据维基百科上 h 指数的定义:h 代表“高引用次数” ,一名科研人员的 h 指数 是指他(她)至少发表了 h 篇论文,并且 至少 有 h 篇论文被引用次数大于等于 h 。如果 h 有多种可能的值,h 指数 是其中最大的那个。
题目链接: 274. H 指数
解题思路及代码:
注意从大到小的排序的写法!!
int 从大到小排序使用sort函数 需要转为Integer
或者先sort后翻转

class Solution {
   

    public int hIndex(int[] citations) {
   
        Integer[] citationsInteger = Arrays.stream(citations).boxed().toArray(Integer[]::new);
        Arrays.sort(citationsInteger,new Comparator<Integer>() {
   
            public int compare(Integer a, Integer b) {
   
                return b - a; // 降序排序
            }
        });
        int result=0;
        for(int i=0;i<citationsInteger.length;i++){
   
            if(citationsInteger[i]>result){
   
                result++;
            }
        }
        return result;
    }
}

相关推荐

  1. 数组|274. H 指数

    2023-12-31 12:46:05       63 阅读
  2. [leetcode 274][H指数]

    2023-12-31 12:46:05       42 阅读
  3. 274. H 指数

    2023-12-31 12:46:05       34 阅读
  4. leetcode274H指数

    2023-12-31 12:46:05       30 阅读
  5. Leetcode274. H 指数(简单易于理解)

    2023-12-31 12:46:05       29 阅读
  6. 【力扣经典面试题】274. H 指数

    2023-12-31 12:46:05       48 阅读
  7. C 指向指针

    2023-12-31 12:46:05       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-31 12:46:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-31 12:46:05       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-31 12:46:05       82 阅读
  4. Python语言-面向对象

    2023-12-31 12:46:05       91 阅读

热门阅读

  1. XXL-JOB学习笔记-基于注解实现自动注册新建任务

    2023-12-31 12:46:05       64 阅读
  2. Fine-Tuning Language Models from Human Preferences

    2023-12-31 12:46:05       48 阅读
  3. 【读书笔记】网空态势感知理论与模型(四)

    2023-12-31 12:46:05       53 阅读
  4. 12 简历错误以及如何避免这些错误

    2023-12-31 12:46:05       56 阅读
  5. C++ enum class 如何使用

    2023-12-31 12:46:05       55 阅读