STUDYING/Algorithm
[Programmers] H-Index
EOZIN
2021. 9. 27. 00:45
728x90
https://programmers.co.kr/learn/courses/30/lessons/42747
import java.util.*;
class Solution {
public int solution(int[] citations) {
int answer = 0;
Arrays.sort(citations);
// System.out.println(Arrays.toString(citations));
for(int i = citations.length; i > 0; i--) {
int h = i;
int lower = 0;
int higher = 0;
for (int j = 0; j < citations.length; j++) {
if (citations[j] >= h) {
higher += 1;
} else {
lower += 1;
}
}
if (higher >= h && lower <= h) {
return h;
}
}
return answer;
}
}