275. H-Index II Medium

@problem@discussion
#Array#Binary Search



1/**
2 * [275] H-Index II
3 *
4 * Given an array of integers citations where citations[i] is the number of citations a researcher received for their i^th paper and citations is sorted in an ascending order, return compute the researcher's h-index.
5 * According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: A scientist has an index h if h of their n papers have at least h citations each, and the other n - h papers have no more than h citations each.
6 * If there are several possible values for h, the maximum one is taken as the h-index.
7 * You must write an algorithm that runs in logarithmic time.
8 *  
9 * Example 1:
10 * 
11 * Input: citations = [0,1,3,5,6]
12 * Output: 3
13 * Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had received 0, 1, 3, 5, 6 citations respectively.
14 * Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
15 * 
16 * Example 2:
17 * 
18 * Input: citations = [1,2,100]
19 * Output: 2
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	n == citations.length
25 * 	1 <= n <= 10^5
26 * 	0 <= citations[i] <= 1000
27 * 	citations is sorted in ascending order.
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/h-index-ii/
33// discuss: https://leetcode.com/problems/h-index-ii/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn h_index(citations: Vec<i32>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_275() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.