Skip to content

Commit c3ac18a

Browse files
authored
Create H-Index.java
1 parent 596920a commit c3ac18a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Array/H-Index.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int hIndex(int[] citations) {
3+
Arrays.sort(citations);
4+
int start = 0, n = citations.length, end = n-1;
5+
int ans = 0;
6+
while (start <= end) {
7+
int mid = start+(end-start)/2;
8+
if (citations[mid] >= n-mid) {
9+
ans = Math.max(ans, n-mid);
10+
end = mid - 1;
11+
} else {
12+
start = mid+1;
13+
}
14+
}
15+
return ans;
16+
}
17+
}

0 commit comments

Comments
 (0)