C++ binary search


  • 0
        int hIndex(vector<int>& citations) {
            int n = citations.size();
            int l = 0;
            int r = n;
            while(l < r){
                int mid = (r - l) / 2 + l;
                if(citations[mid] < n - mid) l = mid + 1;
                else r = mid;
            }
            return n - r;
    

Log in to reply
 

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