每日一题 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; 
    }
};
相关推荐
吞下星星的少年·-·15 小时前
LeetCode 热题 100 最长连续序列(哈希表)
算法·leetcode·散列表
Pniubi16 小时前
力扣25.K个一组反转链表
算法·leetcode·链表
小白的高手之路17 小时前
【LeetCode 热题 100】560. 和为 K 的子数组|前缀和、哈希表(Python)
数据结构·笔记·python·算法·leetcode·力扣·散列表
劲夫学编程21 小时前
leetcode: 字母异位词分组
算法·leetcode
wy_hhxx1 天前
[Leetcode] 动态规划(打家劫舍、0-1背包、完全背包)
算法·leetcode·动态规划·完全背包·0-1背包
Shaoshing1 天前
LeetCode100 32.最长有效括号
java·数据结构·leetcode
小白的高手之路1 天前
【LeetCode 热题 100】240. 搜索二维矩阵 II|矩阵、二分查找、Z 字形查找(Python)
python·算法·leetcode·矩阵·力扣
劲夫学编程1 天前
leetcode:最长连续序列
leetcode·最长连续序列
Navigator_Z2 天前
LeetCode //C - 1328. Break a Palindrome
c语言·算法·leetcode
旖旎夜光4 天前
LeetCode 493: 翻转对 (归并排序) —— 题解
c++·笔记·学习·算法·leetcode·排序算法