274. H-Index
来源:互联网 发布:配电网数据采集与监控 编辑:程序博客网 时间:2024/04/30 08:19
Problem
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 h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.”
For example, given citations = [3, 0, 6, 1, 5], which 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, his h-index is 3.
Note: If there are several possible values for h, the maximum one is taken as the h-index.
Solution
按照定义,排序之后暴力法,暴力法
class Solution {public: int hIndex(vector<int>& citations) { if(citations.empty()) return 0; sort(citations.begin(),citations.end()); int size = citations.size(); int maxEle = *max_element(citations.begin(),citations.end()); int hIndex_ = 0; for(int i = 1;i<=maxEle;++i) { int count = 0; for(int j = size-1;j>=0;--j) { if(citations[j] >=i) ++count; if(count >= i && i>hIndex_) hIndex_ = i; } } return hIndex_; }};
讨论区的方法
带有解释的讨论
首先我们可以知道,一个人的h-index最大只可能是paper的篇数L。
我们使用一个数组,来记录引用数为i的论文的篇数,对于引用数大于paper篇数的情况,统统算在引用数为L的情况中。
然后从L开始,从大到小累加篇数,找到h-index。
class Solution {public: int hIndex(vector<int>& citations) { if(citations.empty()) return 0; int size = citations.size(); vector<int> count(size+1,0); for(int i = 0;i<citations.size();++i) { if(citations[i] > size) { count[size]++; } else { count[citations[i]]++; } } int total = 0; for(int i = size;i>=0;i--) { total+=count[i]; if(total >=i) return i; } return 0; }};
- 274. H-Index & 275. H-Index II
- [leetcode] 274.H-Index
- Leetcode 274. H-Index
- leetcode 274. H-Index
- 274. H-Index
- 274. H-Index
- LeetCode *** 274. H-Index
- 274. H-Index
- 274. H-Index
- 274. H-Index
- 274. H-Index
- leetcode.274. H-Index
- 【leetcode】274. H-Index
- 274. H-Index
- 274. H-Index
- 274. H-Index
- LeetCode - 274. H-Index
- 274. H-Index
- C关键字之const、static、register
- __weak和__block探究与区别
- scope 对象在 AngularJS 中充当数据模型的作用,也就是一般 MVC 框架中 Model 得角色.但又不完全与通常意义上的数据模型一样,因为 $scope 并不处理和操作数据,它只是建立了
- 使用tcmalloc提升mysql性能
- java 动态规划判断股票最大盈利问题
- 274. H-Index
- 指针数组和数组指针的区别
- hadoop学习序曲之java基础篇--java多线程
- PART 2: 使 Shell 能读取命令
- Shiro整合SSH开发4:Realm授权,perms过滤器测试和使用方法讲述
- Android Volley详细解析(一):Volley基本用法
- swift 网络请求&json解析
- 修改Ubuntu中locale转中文为英文
- OSG学习笔记5—使用开关节点