LeetCode 274. H-Index
2016-06-26 12:06
405 查看
Problem: 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 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
Thought:
have an extra space to note bucket[i] papers have i citation, when n, bucket
= times more than n
Reference: https://leetcode.com/discuss/93819/java-bucket-sort-o-n-solution-with-detail-explanation
Code C++:
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
5papers in total and each of them had received
3, 0, 6, 1, 5citations respectively. Since the researcher has
3papers with at least
3citations each and the remaining two with no more than
3citations each, his h-index is
3.
Thought:
have an extra space to note bucket[i] papers have i citation, when n, bucket
= times more than n
Reference: https://leetcode.com/discuss/93819/java-bucket-sort-o-n-solution-with-detail-explanation
Code C++:
class Solution { public: int hIndex(vector<int>& citations) { int n = citations.size(); int* bucket = new int[n+1]; for (int i = 0; i <= n; i++){ bucket[i] = 0; } for (int i = 0; i < citations.size(); i++) { if (citations[i] > n) { bucket ++; } else { bucket[citations[i]]++; } } int count = 0; for (int i = n; n >= 0; i--) { count += bucket[i]; if (count >= i) { return i; } } return 0; } };
相关文章推荐
- 我的 React Native 技能树点亮计划 の React Native 开发 IDE 选型和配置
- 界面美化 —— 布局
- 阶乘的性质
- 我的 React Native 技能树点亮计划 の Javascript 模块管理器 npm
- 重写recyclerview,支持下拉刷新、下拉加载更多、addHeader、addFoot、setEmptyView
- 在Matlab中实现透视变换的方法
- 输入法中的全角和半角对编译的影响
- HTML基本标签(三)
- 送给前线码农的话 - 大牛们的经典语录
- UICollectionViewFlowLayout 默认值测试
- Greenplum中exit,return和label的注意事项
- 阅读sea.js源码小结
- java IO之File类
- CSS样式技巧总结
- js跨域4种解决方案
- Hibernate的批量更新与删除(&&JDBC)
- linux xargs命令
- 用IntelliJ IDEA的GUI Designer写Swing程式
- 整除的判定
- 利用单个三层交换机实现不同vlan和不同网段之间互通(华为和cisco)