Commit a42cc3a 1 parent dd6baa4 commit a42cc3a Copy full SHA for a42cc3a
File tree 1 file changed +16
-14
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +16
-14
lines changed Original file line number Diff line number Diff line change 2
2
3
3
/**
4
4
* 275. H-Index II
5
- * Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
5
+ *
6
+ * Follow up for H-Index: What if the citations array is sorted in ascending order?
7
+ * Could you optimize your algorithm?
6
8
*/
7
9
public class _275 {
8
-
9
- public int hIndex (int [] citations ) {
10
- int left = 0 ;
11
- int len = citations .length ;
12
- int right = len - 1 ;
13
- while (left <= right ) {
14
- int mid = left + (right - left ) / 2 ;
15
- if (citations [mid ] >= (len - mid )) {
16
- right = mid - 1 ;
17
- } else {
18
- left = mid + 1 ;
10
+ public static class Solution1 {
11
+ public int hIndex (int [] citations ) {
12
+ int left = 0 ;
13
+ int len = citations .length ;
14
+ int right = len - 1 ;
15
+ while (left <= right ) {
16
+ int mid = left + (right - left ) / 2 ;
17
+ if (citations [mid ] >= (len - mid )) {
18
+ right = mid - 1 ;
19
+ } else {
20
+ left = mid + 1 ;
21
+ }
19
22
}
23
+ return len - left ;
20
24
}
21
- return len - left ;
22
25
}
23
-
24
26
}
You can’t perform that action at this time.
0 commit comments