-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHIndex.java
56 lines (45 loc) · 1.48 KB
/
HIndex.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
import java.util.stream.*;
class Solution {
public int solution(int[] citations) {
return getHIndex(citations);
}
public int getHIndex(int[] citations) {
Arrays.sort(citations);
int hIndex=0;
for(int i = citations.length-1; i > -1; i--) {
int countOfResearch = citations.length - i; //h번이상 인용된 논문의 수
int hCandidate = Math.min(citations[i],countOfResearch); //논문의 수가 h편이상이 되는값. 두 수의 최소값을 구한다.
hIndex = Math.max(hCandidate,hIndex); //최대의 hIndex를 구한다.
}
return hIndex;
}
}
---
import java.util.*;
import java.util.stream.*;
class Solution {
public int solution(int[] citations) {
return getHIndex(citations);
}
public int getHIndex(int[] citations) {
int countOfResearch = citations.length;
Arrays.sort(citations);
int hIndex=0;
for(int h=0;h<Arrays.stream(citations).max().getAsInt();h++) {
System.out.println(h);
//h번이상 인용된 논문의 수
int count=0;
for(int citation : citations) {
if(citation>=h) count++;
}
//해당 논문이 h편이상
if(count>=h) {
hIndex = h;
continue;
}
return hIndex;
}
return hIndex;
}
}