C++ O(NlogN) simple

  • 0
    class Solution {
        int hIndex(vector<int>& c) {
            int len = c.size();
            if(len==0) return 0;
            sort(c.begin(), c.end(), [](int a, int b){return a>b;});
            int res=-1;
            for(int i=0; i<len; ++i)
               res = max(res, min(i+1, c[i]));
            return res;

Log in to reply

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