-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy path0274-h-index.js
More file actions
26 lines (25 loc) · 762 Bytes
/
0274-h-index.js
File metadata and controls
26 lines (25 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
* 274. H-Index
* https://leetcode.com/problems/h-index/
* Difficulty: Medium
*
* Given an array of integers citations where citations[i] is the number of citations
* a researcher received for their ith paper, return the researcher's h-index.
*
* According to the definition of h-index on Wikipedia: The h-index is defined as the
* maximum value of h such that the given researcher has published at least h papers
* that have each been cited at least h times.
*/
/**
* @param {number[]} citations
* @return {number}
*/
var hIndex = function(citations) {
citations.sort((a, b) => a - b);
for (let i = 0; i < citations.length; i++) {
if (citations[i] >= citations.length - i) {
return citations.length - i;
}
}
return 0;
};