Skip to content

Commit 389b183

Browse files
authored
Update H-Index II
1 parent 6bbcec2 commit 389b183

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

H-Index II

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
class Solution {
22
public int hIndex(int[] citations) {
3-
int lo = 0;
4-
int hi = citations.length - 1;
5-
int length = citations.length - 1;
6-
int hIndex = 0;
7-
while(lo <= hi) {
8-
int mid = lo + (hi - lo)/2;
9-
int h = citations[mid];
10-
int rightL = (length - mid) + 1;
11-
12-
if(h == rightL) {
13-
hIndex = Math.max(hIndex, rightL);
14-
break;
15-
} else if(h < rightL) {
16-
lo = mid + 1;
17-
} else {
18-
hIndex = Math.max(hIndex, rightL);
19-
hi = mid - 1;
20-
}
21-
}
22-
23-
return hIndex;
24-
}
3+
int L=0;
4+
int R=citations.length;
5+
while (L<R){
6+
int mid = (R+L)/2;
7+
int number = citations.length - mid;
8+
if(number == citations[mid]){
9+
return number;
10+
}
11+
if(number < citations[mid]){
12+
R = mid;
13+
}
14+
else{
15+
L = mid+1;
16+
}
17+
}
18+
return citations.length - L;
19+
}
2520
}

0 commit comments

Comments
 (0)