6-lines C++ Solution using hash table


  • 0
    Y
    class Solution {
    public:
        int hIndex(vector<int>& citations) {
            unordered_map<int, int> ht;
            for (auto i:citations) ht[i] = 0;
            for (auto j:ht) for (auto i:citations) if (i >= j.first) ht[j.first]++;
            int h = 0;
            for (auto i:ht)  h = max(h, min(i.first, i.second));    
            return h;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.