汕头seo网站推广,wordpress采集免费版下载,正规seo关键词排名网络公司,新网站备案文章目录 1、描述2、关键字3、思路4、notes5、复杂度6、code 1、描述
给你一个整数数组 citations #xff0c;其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h 指数。
根据维基百科上 h 指数的定义#xff1a;h 代表“高引用次数” … 文章目录 1、描述2、关键字3、思路4、notes5、复杂度6、code 1、描述
给你一个整数数组 citations 其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h 指数。
根据维基百科上 h 指数的定义h 代表“高引用次数” 一名科研人员的 h 指数 是指他她至少发表了 h 篇论文并且 至少 有 h 篇论文被引用次数大于等于 h 。如果 h 有多种可能的值h 指数 是其中最大的那个。 链接
2、关键字
论文被引用的h指数
3、思路
1、直接把每篇论文的引用次数展开构成一行之后竖着统计检查从左往右更新h 2、进行排序之后从大到小遍历 需要满足2个条件 条件一有至少h篇 条件二h篇中每篇至少引用h次
排好序又从大到小遍历h保证条件一 其中直接比较判断保证条件二
4、notes
5、复杂度
时间 方法一O(N2) 方法二O(nlogN) 空间 方法1O(N2) 方法二On数组长度
6、code
# 方法一
class Solution {
public:int hIndex(vectorint citations) {int n citations.size();int max_n 0;for (auto r : citations) { // 求出最多引用次数作为列if (r max_n) {max_n r;}}int res 0;vectorvectorint vec(n, vectorint(max_n, 0));for(int i 0; i n; i) { // 初始化vec二维数组for(int j 0; j max_n; j) {if(j citations[i] ) {vec[i][j] 1;} else{break;}}}for(int j 0; j max_n; j) { // 竖着看去检查int tem 0;for(int i 0; i n; i) {if(vec[i][j] 1) {tem;}}if(tem j 1 j 1 res) { // j从0开始所以j1res j 1;}}return res;}
};方法二
class Solution {
public:int hIndex(vectorint citations) {sort(citations.begin(), citations.end());int n citations.size() - 1;int h 0;while(n 0) {if(citations[n] h) { // 这里是 没有h;}n--;}return h;}
};