来源:力扣(LeetCode)

链接:https://leetcode.cn/problems/h-index-ii

著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

题目的大意是这样的
有一个升序排列的数组citations,返回citations的h指数 h指数:在数组citations中,至少有h个元素,他们的值大于等于h 根据题意即可写出暴力算法
思路:
枚举h指数,h指数的范围应该是多少? [0,citations.size()]
h指数范围的简要证明如下:
为什么0做起点
由题给出的数据范围可知,citations的长度为1~10^5,
虽然不可能存在有0个元素,他们的值大于等于0,但是存在一种情况,给出的数组citations,没有h指数(样例数据中看到的)
为什么citations.size()做终点
因为最好的情况就是至少有citations.size()个元素,他们的值大于等于citations.size()

代码如下


class Solution {
public: bool check(int h,vector<int>& citations){
int len = -1;
for(int i=0;i<citations.size();i++){
if(citations[i]>=h && citations.size()-i == h){
// 得到有len-i+1篇论文至少引用了h次
len = citations.size()-i;
break;
}
}
if(len!=-1)return 1;
else return 0;
} int hIndex(vector<int>& citations) {
// h指数的初始情况
int res = 0; for(int i=citations.size();i>0;i--){
if(check(i,citations)){
res = i;
break;
}
} return res;
}
};

275. H 指数 II--Leetcode_暴力的更多相关文章

  1. Leetcode之二分法专题-275. H指数 II(H-Index II)

    Leetcode之二分法专题-275. H指数 II(H-Index II) 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. ...

  2. Java实现 LeetCode 275 H指数 II

    275. H指数 II 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高 ...

  3. 275 H-Index II H指数 II

    这是 H指数 进阶问题:如果citations 是升序的会怎样?你可以优化你的算法吗? 详见:https://leetcode.com/problems/h-index-ii/description/ ...

  4. [LeetCode] 275. H-Index II H指数 II

    Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...

  5. [Swift]LeetCode275. H指数 II | H-Index II

    Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a ...

  6. 275. H 指数 II--Leetcode_二分

    来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/h-index-ii 著作权归领扣网络所有.商业转载请联系官方授权,非商业转载请注明出处. 题目的大意是 ...

  7. [LeetCode] 274. H-Index H指数

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  8. [LeetCode] H-Index 求H指数

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  9. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

随机推荐

  1. 《Mybatis 手撸专栏》第10章:使用策略模式,调用参数处理器

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 你这代码写的,咋这么轴呢! 说到轴,让我想起初中上学时老师说的话:"你那脑 ...

  2. 论文解读(GraphSMOTE)《GraphSMOTE: Imbalanced Node Classification on Graphs with Graph Neural Networks》

    论文信息 论文标题:GraphSMOTE: Imbalanced Node Classification on Graphs with Graph Neural Networks论文作者:Tianxi ...

  3. 【原创】快速理解Unicode和utf-8的本质

    字符串编码 基本概念 在代码中处理,为了字节统一,都统一使用Unicode 核心:在pyhton中s.encode("utf-8")中的变量实例s必须是已经是Unicode格式,否 ...

  4. Go微服务框架go-kratos实战04:kratos中服务注册和服务发现的使用

    一.简介 关于服务注册和服务发现介绍,我前面的文章有介绍过 - 服务注册和发现的文章. 作为服务中心的软件有很多,比如 etcd,consul,nacos,zookeeper 等都可以作为服务中心. ...

  5. Cabloy-CMS中区块的开发与效果

    关于区块 Cabloy-CMS引入了区块的概念,通过区块可以快速向文章添加各种类型的内容,比如:插入一个地图子页面.插入一首音乐,等等 Cabloy-CMS中的区块可以类比于Wordpress古腾堡编 ...

  6. ACL权限控制

    ALC讲述比较详细 https://zhuanlan.zhihu.com/p/360158311

  7. 【Redis】事件驱动框架源码分析

    aeEventLoop初始化 在server.c文件的initServer函数中,对aeEventLoop进行了初始化: 调用aeCreateEventLoop函数创建aeEventLoop结构体,对 ...

  8. ant design pro生产和开发环境的坑

    1.axios的get请求开发环境会自动带上cookie,但是生产环境则不会,需要手动设置以下代码: axios.defaults.withCredentials=true; 2.models全局和局 ...

  9. python 连接SAP 代码

    def Main(): sap_app = r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe" subproces ...

  10. Linux安装fastdfs集群部署

    过程问题: make: gcc:命令未找到 解决: yum -y install gcc 一.环境和版本: Linux环境:CentOS 7.6 libfastcommon版本:1.0.39 Fast ...