当前位置: 首页 > news >正文

LeetCode每日一题——275. H-Index II

文章目录

    • 一、题目
    • 二、题解

一、题目

Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in ascending order, return the researcher’s h-index.

According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.

You must write an algorithm that runs in logarithmic time.

Example 1:

Input: citations = [0,1,3,5,6]
Output: 3
Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had received 0, 1, 3, 5, 6 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, their h-index is 3.
Example 2:

Input: citations = [1,2,100]
Output: 2

Constraints:

n == citations.length
1 <= n <= 105
0 <= citations[i] <= 1000
citations is sorted in ascending order.

二、题解

class Solution {
public:int hIndex(vector<int>& citations) {int n = citations.size();int left = 0, right = n - 1;while(left <= right){int mid = (left + right) >> 1;int ret = n - mid;if(citations[mid] >= ret) right = mid - 1;else if(citations[mid] < ret) left = mid + 1;}return n - left;}
};
http://www.lryc.cn/news/211790.html

相关文章:

  • 项目添加EZOpenSDK之后就开始报错:could not build module foundation等
  • “智能科技·链接未来”2024中国国际人工智能产品展览会·智博会
  • 华为NAT配置实例(含dhcp、ospf配置)
  • 怎样才能把视频号的视频保存到相册,怎么下载视频号视频两个方法轻松解决
  • 软考系统架构师知识点集锦七:计算机系统基础知识
  • k8s节点已有镜像,但Pod一直在拉取镜像时卡着
  • 用图说话——流程图进阶
  • 深入了解 Elasticsearch 8.1 中的 Script 使用
  • 激光雷达点云基础-点云滤波算法与NDT匹配算法
  • 回收废品抢派单小程序开源版开发
  • 粤嵌实训医疗项目--day04(Vue + SpringBoot)
  • redis加入window服务及删除
  • leetcode-哈希表
  • NOIP2023模拟6联测27 旅行
  • 【表面缺陷检测】钢轨表面缺陷检测数据集介绍(2类,含xml标签文件)
  • SHCTF 2023 新生赛 Web 题解
  • 二叉树题目合集(C++)
  • dbeaver配置es连接org.elasticsearch.xpack.sql.jdbc.EsDriver
  • 有监督学习线性回归
  • 如何在vscode中添加less插件
  • mediapipe 训练自有图像数据分类
  • 【pytorch】torch.gather()函数
  • Mac 安装psycopg2,报错Error: pg_config executable not found.
  • 域名系统 DNS
  • Vue $nextTick 模板解析后在执行的函数
  • VBA技术资料MF76:将自定义颜色添加到调色板
  • zilong-20231030
  • 目标检测算法发展史
  • React 生成传递给无障碍属性的唯一 ID
  • 十种排序算法(1) - 准备测试函数和工具