【java】力扣 H指数

文章目录

题目链接

274.H指数

题目描述

思路

设置n为citations的长度,也就是发表论文的篇数,h肯定是不能超过n的,所以当有引用次数大于n时,我们要看成n,

要创建一个数组arr,来存储引用次数的篇数,统计min(citationsi,n)出先得次数,比如引用次数是 5次的有两个,引用次数是3次的有一个

s为引用次数>=h的文章数,h=n,采用倒数的循坏,每次循环,把arri加到s种,只要s>=h成立,返回的i就是所求的h指数

代码

java 复制代码
public int hIndex(int[] citations) {
        int n = citations.length;
        int[] arr = new int[n+1];
        for(int c:citations){
            arr[Math.min(c,n)]++;
        }
        int s=0;
        for(int h =n;;h--){
            s +=arr[h];
            if(s>=h){
                return h;
            }
        }
    }
相关推荐
蓝田~20 分钟前
大模型本地部署与远程调用 — 从 API 到 Agent
java·人工智能·claude·claude code
码农进化录27 分钟前
Java 程序员的 AI 进化论 | Spring Boot 接入 OpenAI 的六个坑,全帮你踩了
java·spring boot·openai
To_OC34 分钟前
LC 22 括号生成:刷完这道题,我终于搞懂回溯剪枝了
javascript·算法·leetcode
疯狂成瘾者36 分钟前
Java 常见集合方法
java·windows·python
从此以后自律37 分钟前
ConcurrentHashMap 超详细详解
java
To_OC43 分钟前
LC 39 组合总和:回溯入门必刷题,我踩过的两个坑都在这了
javascript·算法·leetcode
兰令水1 小时前
hot100【acm版】【2026.7.14打卡-java版本】
java·数据结构·算法·leetcode·面试
cpp_25011 小时前
P10098 [ROIR 2023] 地铁建设 (Day 2)
数据结构·c++·算法·贪心·二分答案·洛谷题解
thefool1122662 小时前
Java 数组是引用类型
java
cfm_29142 小时前
Spring监听器
java·spring boot·后端