当前位置:网站首页>【leetcode】275. H index II
【leetcode】275. H index II
2022-06-26 23:45:00 【Chinese fir sauce_】
subject :
Give you an array of integers citations , among citations[i] Indicates the researcher's second opinion i The number of citations of this paper ,citations According to Ascending order . Calculate and return the researcher's h Index .
h The definition of index :h representative “ High citations ”(high citations), A researcher's h The index refers to him ( she ) Of (n In a paper ) All in all h At least one of the papers was cited h Time . And the rest n - h Number of citations per paper No more than h Time .
Tips : If h There are many possible values ,h Index It's the biggest one .
Please design and implement an algorithm with logarithmic time complexity to solve this problem .
Example 1:
Input :citations = [0,1,3,5,6]
Output :3
explain : The given array indicates that the researcher has a total of 5 Papers , Each paper is cited accordingly 0, 1, 3, 5, 6 Time .
Because the researchers have 3 Each paper At least It's quoted 3 Time , The other two papers are cited Not more than 3 Time , So her h The index is 3 .
Example 2:
Input :citations = [1,2,100]
Output :2
Method 1 :
violence
class Solution {
public int hIndex(int[] citations) {
int n = citations.length;
int count = 0;
for(int i = n-1; i>= 0;i--){
if(count >= citations[i]) return count;
count++;
}
return count;
}
}
Method 2 :
Two points
The question : For the biggest h, Make the array have h Elements are not less than h
class Solution {
public int hIndex(int[] citations) {
/** Dichotomy : */
int n = citations.length;
int l = 0, r = n - 1;
while(l <= r){
int mid = (l+r) / 2;
// len - mid For from mid To len To the number of papers , If you want to len - mid As hIndex
// It is required to start from mid To len The lowest cited paper in citations Is greater than or equal to len - mid( That is to say citations[mid]>=paperCnt).
// If this condition is met , Let's try to make hIndex Bigger , That is to say mid To the left , Then let's adjust end = mid - 1
// If the conditions are not met , We let mid Move to the right , such paperCnt Less , meanwhile citations[mid] It's big too , Let's look again from mid Start to len Can you act as hIndex
if(citations[mid] >= n - mid) r = mid - 1;
else l = mid + 1;
}
return n - l;
}
}
边栏推荐
- Unity初学者肯定能用得上的50个小技巧
- 一篇文章带你学会容器逃逸
- 利用burp精准定位攻击者
- 颜色搭配和相关问题
- typora设置标题自动编号
- NPM command prompt error: eacces: permission denied
- Introduction de l'opérateur
- 300 questions lesson 3 vector group
- Selenium电脑上怎么下载-Selenium下载和安装图文教程[超详细]
- Is it reliable to open an account for stock trading on the mobile phone? Is it safe to open an account for stock trading on the Internet
猜你喜欢

论文学习——降雨场次划分方法对降雨控制率的影响分析

Can't write to avoid killing and can easily go online CS through defender

From bitmap to bloom filter, C # implementation

阿里云服务器的购买、基本配置、(xshell)远程连接、搭建环境

xshell的安装、xftp的安装

固有色和环境色

浅谈分布式系统开发技术中的CAP定理
![[microservice]eureka](/img/60/e5fa18d004190d4dadebfb16b93550.png)
[microservice]eureka

Solid and ambient colors

50 tips that unity beginners can definitely use
随机推荐
为什么EDR需要深度防御来打击勒索软件?
Openpyxl module
Installation of xshell and xftp
泰国安全又划算的支付方式
大咖讲 | 最前沿的昇思MindSpore开源社区运营的经验分享,快拿出小本本记录呀!
[machine learning] - Introduction to vernacular and explanation of terms
想买股票请问在券商公司的哪里开户佣金低更安全
Operations research says that in issue 66, Behrman also has "speech phobia"?
Introduction de l'opérateur
Let agile return to its original source -- Some Thoughts on reading the way of agile neatness
go语言的服务发现、存储引擎、静态网站
BS-GX-016基于SSM实现教材管理系统
Bs-gx-016 implementation of textbook management system based on SSM
Can I open an account for stock trading on my mobile phone? Is it safe to open an account for stock trading on the Internet
Unity4.6版本下载
NPM command prompt error: eacces: permission denied
UnityEditor编辑器扩展-表格功能
[microservices] Understanding microservices
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
邮箱附件钓鱼常用技法