每日一题 274. H 指数

274. H 指数

排序后就很解决

cpp 复制代码
class Solution {
public:
    int hIndex(vector<int>& citations) {
        int n = citations.size();
        sort(citations.begin(),citations.end());
        int ans = 0;
        for(int i=n-1;i>=0;--i){
            int h = n- i;
            if(citations[i] >= h){
                ans = h;
            }else{
                break;
            }
        }
        return ans; 
    }
};
相关推荐
Little At Air2 小时前
LeetCode 30. 串联所有单词的子串 | 困难 C++实现
算法·leetcode·职场和发展
手握风云-2 小时前
优选算法的层序之径:队列专题
数据结构·算法·leetcode
6Hzlia2 小时前
【Hot 100 刷题计划】 LeetCode 74. 搜索二维矩阵 | C++ 二分查找 (一维展开法)
c++·leetcode·矩阵
北顾笙9802 小时前
day20-数据结构力扣
数据结构·算法·leetcode
生信研究猿3 小时前
leetcode 121.买卖股票的最佳时机
算法·leetcode·职场和发展
sheeta19983 小时前
LeetCode 每日一题笔记 日期:2026.04.09 题目:3655.区间乘法查询后的异或二
笔记·算法·leetcode
穿条秋裤到处跑3 小时前
每日一道leetcode(2026.04.08):区间乘法查询后的异或 I
算法·leetcode
6Hzlia3 小时前
【Hot 100 刷题计划】 LeetCode 240. 搜索二维矩阵 II | C++ 巧妙利用单调性 (BST 法)
c++·leetcode·矩阵
小肝一下4 小时前
每日两道力扣,day7
数据结构·c++·算法·leetcode·双指针·hot100·接雨水,四数之和
Ricky111zzz1 天前
leetcode学python记录1
python·算法·leetcode·职场和发展