Leetcode 274. 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 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.
计算H-index,一个关于科研人员的指标。
采用计数排序的思想解决。
class Solution {
public:
int hIndex(vector<int>& citations) {
vector<int> cnt(citations.size() + 2, 0);
for(int i = 0; i < citations.size(); i++)
{
if(citations[i] > citations.size()) cnt[citations.size()]++;
else cnt[citations[i]]++;
}
for(int i = citations.size(); i >= 0; i--)
{
cnt[i] += cnt[i + 1];
if(cnt[i] >= i) return i;
}
return 0;
}
};
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- JavaScript的内存管理
- 实现自己的Vue Router -- Vue Router原理解析
- G级大文件分割器 + 核心源码
- 前端也能学算法:JS版常见排序算法-冒泡,插入,快排,归并
- 前端也能学算法:JS版链表
- 将二进制文件加入VC资源后释放执行
- JavaScript中的函数式编程
- JavaScript中的compose函数和pipe函数
- 常用JS函数-数组扁平化,缓存函数,柯里化函数,防抖和节流函数
- JavaScript单元测试及原理
- 前端进阶知识汇总
- 前端也能学算法:由浅入深讲解动态规划
- 轻松理解JS中的面向对象,顺便搞懂prototype和__proto__
- 前端也能学算法:由浅入深讲解贪心算法
- web.py指南性说明