4 lines O(NlogN) solution in C++


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

Log in to reply
 

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