Skip to content

Commit a42cc3a

Browse files
refactor 275
1 parent dd6baa4 commit a42cc3a

File tree

1 file changed

+16
-14
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+16
-14
lines changed

src/main/java/com/fishercoder/solutions/_275.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22

33
/**
44
* 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?
68
*/
79
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+
}
1922
}
23+
return len - left;
2024
}
21-
return len - left;
2225
}
23-
2426
}

0 commit comments

Comments
 (0)