12ms c++


  • 0
    B
    class Solution {
    public:
        int hIndex(vector<int>& citations)
        {
            int len=citations.size();
            if (len==0) return 0;
            int left=0,right=len;
            while (left<right)
            {
                int mid=(right-left)/2+left;
                if (citations[mid]>=len-mid) right=mid;
                else left=mid+1;
            }
            return len-right;
        }
    };
    

Log in to reply
 

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