每日一题 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; 
    }
};
相关推荐
小欣加油2 小时前
leetcode 1493 删掉一个元素以后全为1的最长子数组
c++·算法·leetcode
YuTaoShao8 小时前
【LeetCode 热题 100】152. 乘积最大子数组——(解法一)递推
java·算法·leetcode·职场和发展
尘世闲鱼10 小时前
移动零【三种思路】
c++·leetcode
flashlight_hi1 天前
LeetCode 分类刷题:2529. 正整数和负整数的最大计数
python·算法·leetcode
野犬寒鸦1 天前
力扣hot100:搜索二维矩阵与在排序数组中查找元素的第一个和最后一个位置(74,34)
java·数据结构·算法·leetcode·list
Keying,,,,1 天前
力扣hot100 | 图论 | 200. 岛屿数量、994. 腐烂的橘子、207. 课程表、208. 实现 Trie (前缀树)
算法·leetcode·图论
楼田莉子1 天前
C++算法学习专题:滑动窗口
开发语言·数据结构·c++·学习·算法·leetcode
超级皮皮2 天前
力扣热题之stack
算法·leetcode·职场和发展
YuTaoShao2 天前
【LeetCode 热题 100】139. 单词拆分——(解法一)记忆化搜索
java·算法·leetcode·职场和发展
圣保罗的大教堂2 天前
leetcode 1277. 统计全为 1 的正方形子矩阵 中等
leetcode