274. H-Index Medium

@problem@discussion
#Array#Sorting#Counting Sort



1/**
2 * [274] H-Index
3 *
4 * Given an array of integers citations where citations[i] is the number of citations a researcher received for their i^th paper, 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 *  
8 * Example 1:
9 * 
10 * Input: citations = [3,0,6,1,5]
11 * Output: 3
12 * Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.
13 * 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.
14 * 
15 * Example 2:
16 * 
17 * Input: citations = [1,3,1]
18 * Output: 1
19 * 
20 *  
21 * Constraints:
22 * 
23 * 	n == citations.length
24 * 	1 <= n <= 5000
25 * 	0 <= citations[i] <= 1000
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/h-index/
31// discuss: https://leetcode.com/problems/h-index/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn h_index(citations: Vec<i32>) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_274() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.