4ms c++


  • 0
    B
    class Solution {
    public:
        int hIndex(vector<int>& citations)
        {
            if (citations.size()==0) return 0;
            int ans=-INT_MAX;
            sort(citations.begin(),citations.end());
            for(int i=citations.size()-1;i>=0;i--)
            {
                //cout<<"i= "<<i<<",count= "<<citations.size()-i<<endl;
                //cout<<"value= "<<citations[i]<<endl;
                int tmp;
                if (citations.size()-i<citations[i])
                    tmp = citations.size()-i;
                else tmp=citations[i];
                if (tmp>ans) ans=tmp;
            }
            return ans;
        }
    };
    

Log in to reply
 

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