func hIndex(citations []int) int { // Target: find the first h that h <= citations[n-h] n := len(citations) beg, end := 0, n for beg < end { mid := beg + (end-beg)/2 h, citation := n-mid, citations[mid] if h < citation { end = mid } else if citation < h { beg = mid + 1 } else { return h } } return n - beg }