#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 怎么肥四 上瘾?
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· 本地部署 DeepSeek:小白也能轻松搞定!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 从 Windows Forms 到微服务的经验教训
· 李飞飞的50美金比肩DeepSeek把CEO忽悠瘸了,倒霉的却是程序员
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee