Skip to content

Commit 8a0a09a

Browse files
committed
Add solution #274
1 parent 02d680b commit 8a0a09a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
264|[Ugly Number II](./0264-ugly-number-ii.js)|Medium|
162162
268|[Missing Number](./0268-missing-number.js)|Easy|
163163
273|[Integer to English Words](./0273-integer-to-english-words.js)|Hard|
164+
274|[H-Index](./0274-h-index.js)|Medium|
164165
278|[First Bad Version](./0278-first-bad-version.js)|Medium|
165166
283|[Move Zeroes](./0283-move-zeroes.js)|Easy|
166167
290|[Word Pattern](./0290-word-pattern.js)|Easy|

solutions/0274-h-index.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 274. H-Index
3+
* https://leetcode.com/problems/h-index/
4+
* Difficulty: Medium
5+
*
6+
* Given an array of integers citations where citations[i] is the number of citations
7+
* a researcher received for their ith paper, return the researcher's h-index.
8+
*
9+
* According to the definition of h-index on Wikipedia: The h-index is defined as the
10+
* maximum value of h such that the given researcher has published at least h papers
11+
* that have each been cited at least h times.
12+
*/
13+
14+
/**
15+
* @param {number[]} citations
16+
* @return {number}
17+
*/
18+
var hIndex = function(citations) {
19+
citations.sort((a, b) => a - b);
20+
for (let i = 0; i < citations.length; i++) {
21+
if (citations[i] >= citations.length - i) {
22+
return citations.length - i;
23+
}
24+
}
25+
return 0;
26+
};

0 commit comments

Comments
 (0)