面试经典150题——Day11

文章目录

一、题目

274. H-Index

Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.

According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.

Example 1:

Input: citations = [3,0,6,1,5]

Output: 3

Explanation: [3,0,6,1,5] 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, their h-index is 3.

Example 2:

Input: citations = [1,3,1]

Output: 1

Constraints:

n == citations.length

1 <= n <= 5000

0 <= citations[i] <= 1000

题目来源:leetcode

二、题解

cpp 复制代码
class Solution {
public:
    int hIndex(vector<int>& citations) {
        int n = citations.size();
        sort(citations.begin(),citations.end());
        int hIndex = 0;
        for(int i = 0;i < n;i++){
            //剩余几篇文章
            int paperNums = n - i;
            //若当前引用值已经大于等于剩余文章数
            if(citations[i] >= paperNums) return paperNums;
            if(paperNums >= citations[i] && citations[i] > hIndex){
                hIndex = citations[i];
            }
        }
        return hIndex;
    }
};
相关推荐
mjhcsp32 分钟前
C++ 循环结构:控制程序重复执行的核心机制
开发语言·c++·算法
立志成为大牛的小牛33 分钟前
数据结构——四十一、分块查找(索引顺序查找)(王道408)
数据结构·学习·程序人生·考研·算法
xier_ran1 小时前
深度学习:RMSprop 优化算法详解
人工智能·深度学习·算法
地平线开发者1 小时前
不同传感器前中后融合方案简介
算法·自动驾驶
Mr_WangAndy1 小时前
C++_chapter15_C++重要知识点_lambda,initializer_list
c++·lambda·初始化列表
地平线开发者1 小时前
征程 6X 常见 kernel panic 问题
算法·自动驾驶
Maple_land1 小时前
第1篇:Linux工具复盘上篇:yum与vim
linux·运维·服务器·c++·centos
hggngx548h2 小时前
有哪些C++20特性可以在Dev-C++中使用?
开发语言·c++·c++20
com_4sapi2 小时前
2025 权威认证头部矩阵系统全景对比发布 双榜单交叉验证
大数据·c语言·人工智能·算法·矩阵·机器人
前端小L2 小时前
二分查找专题(九):“降维”的魔术!将二维矩阵“拉平”为一维
数据结构·算法