当前位置:网站首页>【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;
}
}
边栏推荐
- [microservices] understanding microservices
- Why don't I recommend going to sap training institution for training?
- 串口调试工具 mobaxterm 下载
- 股票开户有哪些优惠活动?手机开户安全么?
- The client implements client Go client type definition connection
- 软件工程导论——第四章——形式化说明技术
- 代码之外:写作是倒逼成长的最佳方式
- [710. random numbers in the blacklist]
- Implement the queue through two stacks
- Service discovery, storage engine and static website of go language
猜你喜欢
Thesis study -- Analysis of the influence of rainfall field division method on rainfall control rate
Installation of xshell and xftp
Common techniques of email attachment phishing
[微服务]Nacos
通过两个stack来实现Queue
Let agile return to its original source -- Some Thoughts on reading the way of agile neatness
泰国安全又划算的支付方式
Redcap is ready to come out. It is indispensable to build a "meta universe"
大咖讲 | 最前沿的昇思MindSpore开源社区运营的经验分享,快拿出小本本记录呀!
开放世界机甲游戏-Phantom Galaxies
随机推荐
【710. 黑名单中的随机数】
想买股票请问在券商公司的哪里开户佣金低更安全
电子协会 C语言 1级 29 、 对齐输出
在线上买养老年金险正规安全吗?有没有保单?
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
不同的子序列问题I
不会写免杀也能轻松过defender上线CS
Which securities dealers recommend? Is it safe to open an account online now?
互联网行业,常见含金量高的证书,看看你有几个?
Would you like to buy stocks? Where do you open an account in a securities company? The Commission is lower and safer
Why does EDR need defense in depth to combat ransomware?
利用burp精准定位攻击者
go语言中的私聊功能处理
Wechat applet automatically generates punch in Poster
PHP code audit series (I) basis: methods, ideas and processes
[微服务]Nacos
Redcap is ready to come out. It is indispensable to build a "meta universe"
A simple and crude method for exporting R language list to local
Cvpr2022 stereo matching of asymmetric resolution images
xshell的安装、xftp的安装