Skip to content

Commit d31f1bf

Browse files
committed
Create 275. H 指数 II.js
1 parent 3e5c44c commit d31f1bf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

275. H 指数 II.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number[]} citations
3+
* @return {number}
4+
*/
5+
var hIndex = function (citations) {
6+
let i = 0;
7+
let j = citations.length - 1;
8+
while (i <= j) {
9+
const mid = (i + j) >> 1;
10+
if (citations[mid] === citations.length - mid) {
11+
return citations.length - mid;
12+
} else if (citations[mid] < citations.length - mid) {
13+
i = mid + 1;
14+
} else {
15+
j = mid - 1;
16+
}
17+
}
18+
19+
return citations.length - i;
20+
};

0 commit comments

Comments
 (0)