Skip to content

Commit 29fe46f

Browse files
authored
Update 274-h-index.js
1 parent 44bfa5a commit 29fe46f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

274-h-index.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/**
2+
* @param {number[]} citations
3+
* @return {number}
4+
*/
5+
const hIndex = function(citations) {
6+
const n = citations.length
7+
const arr = Array(n + 1).fill(0)
8+
for(let e of citations) {
9+
if(e >= n) arr[n]++
10+
else arr[e]++
11+
}
12+
for(let i = n, sum = 0; i >= 0; i--) {
13+
sum += arr[i]
14+
if(sum >= i) return i
15+
}
16+
return 0
17+
};
18+
19+
// another
20+
121
/**
222
* @param {number[]} citations
323
* @return {number}

0 commit comments

Comments
 (0)