274. H-Index

class Solution {
public:
    int hIndex(vector<int>& citations) {
        int n = citations.size();
        vector<int> buck(n+1, 0);
        for (auto c : citations) {
            if (c > n)
                c = n;
            buck[c]++;
        }
        int cnt = 0;
        for (int i = n; i >= 0; --i) {
            cnt += buck[i];
            if (cnt >= i)
                return i;
        }
        return -1;  // never reach here
    }
};

 

posted @ 2018-05-22 13:37  JTechRoad  阅读(70)  评论(0编辑  收藏  举报