File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 161
161
264|[ Ugly Number II] ( ./0264-ugly-number-ii.js ) |Medium|
162
162
268|[ Missing Number] ( ./0268-missing-number.js ) |Easy|
163
163
273|[ Integer to English Words] ( ./0273-integer-to-english-words.js ) |Hard|
164
+ 274|[ H-Index] ( ./0274-h-index.js ) |Medium|
164
165
278|[ First Bad Version] ( ./0278-first-bad-version.js ) |Medium|
165
166
283|[ Move Zeroes] ( ./0283-move-zeroes.js ) |Easy|
166
167
290|[ Word Pattern] ( ./0290-word-pattern.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments