-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathH-Index.java
More file actions
30 lines (29 loc) · 819 Bytes
/
H-Index.java
File metadata and controls
30 lines (29 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//O(N)
public class Solution {
public int hIndex(int[] citations) {
int[] count = new int[citations.length + 1];
for (int i = 0; i < citations.length; ++i) {
count[Math.min(citations[i], citations.length)]++;
}
int maxIndex = 0;
for (int i = count.length - 1; i >= 0; --i) {
maxIndex += count[i];
if (maxIndex >= i) {
return i;
}
}
return maxIndex;
}
}
//O(NlogN)
public class Solution {
public int hIndex(int[] citations) {
Arrays.sort(citations);
for (int i = citations.length - 1; i >= 0; --i) {
if (citations[i] < (citations.length - i)) {
return citations.length - i - 1;
}
}
return citations.length;
}
}