My cpp code using sort


  • 0
    C
    class Solution {
    public:
        int hIndex(vector<int>& citations) 
        {
            if(citations.size() == 0) return 0;
            
            std::sort(citations.begin(), citations.end());
            
            int res = 0;
            for(int i=0; i < citations.size(); i++)
            {
                int h = citations.size() - i;
                if(citations[i] >= h) return h;
            }
            
            return res;
        }
    };

Log in to reply
 

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