每日一题 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; 
    }
};
相关推荐
而后笑面对12 小时前
力扣2025.10.19每日一题
算法·leetcode·职场和发展
·白小白13 小时前
力扣(LeetCode) ——11.盛水最多的容器(C++)
c++·算法·leetcode
玩镜的码农小师兄16 小时前
[从零开始面试算法] (04/100) LeetCode 136. 只出现一次的数字:哈希表与位运算的巅峰对决
c++·算法·leetcode·面试·位运算·hot100
无敌最俊朗@1 天前
数组-力扣hot56-合并区间
数据结构·算法·leetcode
码农多耕地呗1 天前
力扣94.二叉树的中序遍历(递归and迭代法)(java)
数据结构·算法·leetcode
微笑尅乐1 天前
BFS 与 DFS——力扣102.二叉树的层序遍历
leetcode·深度优先·宽度优先
白云千载尽1 天前
leetcode 912.排序数组
算法·leetcode·职场和发展
代码充电宝1 天前
LeetCode 算法题【简单】290. 单词规律
java·算法·leetcode·职场和发展·哈希表
And_Ii1 天前
LeetCode 3397. 执行操作后不同元素的最大数量
数据结构·算法·leetcode
额呃呃1 天前
leetCode第33题
数据结构·算法·leetcode