File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 219
219
268|[ Missing Number] ( ./0268-missing-number.js ) |Easy|
220
220
273|[ Integer to English Words] ( ./0273-integer-to-english-words.js ) |Hard|
221
221
274|[ H-Index] ( ./0274-h-index.js ) |Medium|
222
+ 275|[ H-Index II] ( ./0275-h-index-ii.js ) |Medium|
222
223
278|[ First Bad Version] ( ./0278-first-bad-version.js ) |Medium|
223
224
282|[ Expression Add Operators] ( ./0282-expression-add-operators.js ) |Hard|
224
225
283|[ Move Zeroes] ( ./0283-move-zeroes.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 275. H-Index II
3
+ * https://leetcode.com/problems/h-index-ii/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an array of integers citations where citations[i] is the number of citations a
7
+ * researcher received for their ith paper and citations is sorted in ascending order,
8
+ * return the researcher's h-index.
9
+ *
10
+ * According to the definition of h-index on Wikipedia: The h-index is defined as the
11
+ * maximum value of h such that the given researcher has published at least h papers
12
+ * that have each been cited at least h times.
13
+ *
14
+ * You must write an algorithm that runs in logarithmic time.
15
+ */
16
+
17
+ /**
18
+ * @param {number[] } citations
19
+ * @return {number }
20
+ */
21
+ var hIndex = function ( citations ) {
22
+ let start = 0 ;
23
+
24
+ for ( let end = citations . length - 1 ; start <= end ; ) {
25
+ const middle = Math . floor ( ( start + end ) / 2 ) ;
26
+ if ( citations . length - middle - 1 < citations [ middle ] ) {
27
+ end = middle - 1 ;
28
+ } else {
29
+ start = middle + 1 ;
30
+ }
31
+ }
32
+
33
+ return citations . length - start ;
34
+ } ;
You can’t perform that action at this time.
0 commit comments