[문제링크 - 프로그래머스 - H-Index] https://school.programmers.co.kr/learn/courses/30/lessons/42747
import java.util.*;
class Solution {
public int solution(int[] citations) {
int answer = 0;
Arrays.sort(citations);
for(int i=0; i<citations[citations.length-1]; i++){
for(int j=0; j<citations.length; j++){
if(citations[j] == i){
if(j+1 <= i && (citations.length-j) >= i) answer = i;
} else if(citations[j] > i){
if(j <= i && (citations.length-j) >= i) answer = i;
}
}
}
return answer;
}
}
h
번 이상 인용된 논문이 h
편 이상이고 나머지 논문이 h
번 이하 인용 이라는 말을 잘못 이해해서 h번 보다 낮은 경우의 수도 조사했었다.class Solution {
public int solution(int[] citations) {
int answer = 0;
Arrays.sort(citations);
for(int i=0; i<citations.length; i++){
int smaller = Math.min(citations[i], citations.length-i);
answer = Math.max(answer, smaller);
}
return answer;
}
}