문제 풀이/프로그래머스
[프로그래머스] H-Index(JAVA)
27200
2024. 4. 28. 15:55
https://school.programmers.co.kr/learn/courses/30/lessons/42747#qna
풀이
import java.util.*;
class Solution {
public int solution(int[] citations) {
int answer = 0;
Arrays.sort(citations);
for(int i = 0; i < citations.length; i++) {
int h = citations.length - i;
if(citations[i] >= h) {
answer = h;
break;
}
}
return answer;
}
}
h번 이상 인용 되는 횟수를 구하기 위해 총 길이에서 빼고 이를 citations[i] 가 넘어가는 순간 정답을 리턴하게 된다.
생각보단 문제를 정확히 이해하는게 꽤나 포인트가 되는 문제라고 느껴졌다.