leetcode

    xiaoxiao2021-03-25  195

    题意:

    题意和上一篇一样,但是多了个条件,现在数组是升序。

    分析:

    对于排好序的数组。

    索引值大于等于h的文章数==h

    即      len -  index     ==  cadidate[ index ]  

    public class Solution { public int hIndex(int[] citations) { int len = citations.length; int low = 0; int high = len - 1; while (low <= high) { int mid = low + (high - low) / 2; if (citations[mid] == len - mid) { return len - mid; } else if (citations[mid] < len - mid) { low = mid + 1; } else { high = mid - 1; } } return len - low; } }    

    转载请注明原文地址: https://ju.6miu.com/read-1192.html

    最新回复(0)