O(NlogN) 12ms solution


  • 10
    A
    class Solution {
    public:
        int hIndex(vector<int>& citations) {
            if(citations.empty())
                return 0;
            sort(citations.begin(), citations.end());
            int n=citations.size();
            int i=0;
            while(i<n && citations[i]<(n-i)) i++;
            return n-i;
        }
    };

Log in to reply
 

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