#Leetcode# 274. H-Index

https://leetcode.com/problems/h-index/

 

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.

According to the definition of h-index on Wikipedia: "A scientist has index h if hof his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each."

Example:

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

Note: If there are several possible values for h, the maximum one is taken as the h-index.

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
    int hIndex(vector<int>& citations) {
        int n = citations.size();
        if(n == 0) return 0;
        int cnt = 0;
        sort(citations.begin(), citations.end());
        for(int i = 0; i < n; i ++) {
            if(citations[i] == 0) cnt ++;
            if(citations[i] >= (n - i))
                return min(n - i, citations[i]);
        }
        if(cnt == n) return 0;
        return 1;
    }
};

  什么时候才能把情况想的全一点呢 但是好像逐渐沉迷怼着数据 debug 怎么肥四 上瘾?

 

posted @   丧心病狂工科女  阅读(118)  评论(0编辑  收藏  举报
编辑推荐:
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
阅读排行:
· 本地部署 DeepSeek:小白也能轻松搞定!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 从 Windows Forms 到微服务的经验教训
· 李飞飞的50美金比肩DeepSeek把CEO忽悠瘸了,倒霉的却是程序员
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
点击右上角即可分享
微信分享提示