LeetCode 274. H 指数

题目链接:点击这里

AC代码:

class Solution {
    
    
public:
    int hIndex(vector<int>& citations) {
    
    
        int n = citations.size();
        if(n == 0)  return 0;

        sort(citations.begin(), citations.end());
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
    
    
            int h = n - i;
            if(citations[i] >= h)
            {
    
    
                ans = h;
                break;
            }
        }
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/qq_42815188/article/details/108226169
今日推荐