File tree 1 file changed +17
-22
lines changed
1 file changed +17
-22
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
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
+ }
25
20
}
You can’t perform that action at this time.
0 commit comments