Clean c++ O(n) solution


  • 0
    int hIndex(vector<int>& citations) {
        int size = citations.size();
        vector<int> count(size + 1);
        for (auto &c : citations)
            count[0]++;
            if (c <= size)
                count[c]--;
        int current = count[0], index = 1;
        while (index <= size && current >= index)
            current += count[index++];
        return index - 1;
    }
    

Log in to reply
 

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