난이도: 중간 (Medium)
정수 배열 citations가 주어집니다.
citations[i]는 연구자의 i번째 논문이 받은 인용 수를 나타냅니다.
연구자의 H-Index를 반환하세요.
📌 H-Index란? (Wikipedia 기준 정의)
H-Index는 다음 조건을 만족하는 가장 큰 정수 h입니다:
연구자가 최소 h편의 논문을 가졌고,
그 각각이 h번 이상 인용되었을 때, 그 사람의 H-Index는 h입니다.
Input: citations = [3,0,6,1,5]
Output: 3
Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.
Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
설명: 총 5편의 논문이 있고, 인용 수는 각각 [3, 0, 6, 1, 5]입니다.
이 중 최소 3편의 논문이 각각 3회 이상 인용되었고,
나머지 2편은 3회 이하 인용되었기 때문에,
H-Index는 3입니다.
Input: citations = [1,3,1]
Output: 1
설명: 1번 이상 인용된 논문이 2편 있지만,
2번 이상 인용된 논문은 1편뿐이므로,
H-Index는 1입니다.
n == citations.length
1 <= n <= 5000
0 <= citations[i] <= 1000
var hIndex = function(citations) {
citations.sort((a, b) => b - a); // 내림차순 정렬
for (let i = 0; i < citations.length; i++) {
if (citations[i] < i + 1) {
return i;
}
}
return citations.length;
};
정렬을 기반으로한 조건탐색 문제로
핵심은