> For the complete documentation index, see [llms.txt](https://protegejj.gitbook.io/algorithm-practice/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://protegejj.gitbook.io/algorithm-practice/leetcode/binary-search/275-h-index-ii.md).

# 275    H-Index II

## 275. [H-Index II](https://leetcode.com/problems/h-index-ii/description/)

## 1. Question

**Follow up** for [H-Index](https://leetcode.com/problems/h-index/) :What if the`citations`array is sorted in ascending order? Could you optimize your algorithm?

## 2. Implementation

**(1) Binary Search**

```java
class Solution {
    public int hIndex(int[] citations) {
        if (citations == null || citations.length == 0) {
            return 0;
        }

        int n = citations.length;
        int start = 0, end = citations.length - 1, mid = 0;

        while (start + 1 < end) {
            mid = start + (end - start) / 2;

            if (citations[mid] < n - mid) {
                start = mid + 1;
            }
            else {
                end = mid;
            }
        }

        if (citations[start] >= n - start) {
            return n - start;
        }
        else if (citations[end] >= n - end) {
            return n - end;
        }
        else {
            return 0;
        }
    }
}
```

## 3. Time & Space Complexity

**Binary Search:** 时间复杂度O(logn), 空间复杂度O(1)
