每日一题 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热题100-寻找两个正序数组的中位数
算法·leetcode·职场和发展
踩坑记录3 小时前
leetcode hot100 寻找两个正序数组的中位数 hard 二分查找 双指针
leetcode
superior tigre6 小时前
78 子集
算法·leetcode·深度优先·回溯
superior tigre7 小时前
739 每日温度
算法·leetcode·职场和发展
6Hzlia8 小时前
【Hot 100 刷题计划】 LeetCode 15. 三数之和 | C++ 排序+双指针
c++·算法·leetcode
北顾笙9809 小时前
day37-数据结构力扣
数据结构·算法·leetcode
6Hzlia11 小时前
【Hot 100 刷题计划】 LeetCode 189. 轮转数组 | C++ 三次反转经典魔法 (O(1) 空间)
c++·算法·leetcode
m0_6294947312 小时前
LeetCode 热题 100-----13.最大子数组和
数据结构·算法·leetcode
田梓燊12 小时前
力扣:94.二叉树的中序遍历
数据结构·算法·leetcode
khalil102012 小时前
代码随想录算法训练营Day-38动态规划06 | 322. 零钱兑换、279.完全平方数、139.单词拆分、多重背包、总结
数据结构·c++·算法·leetcode·动态规划