Skip to content
Algorithm in JavaScript
Basic

274. H-Index

정렬 후 전체 범위를 이진 탐색하며 h-index 조건을 만족하는 최대 값을 찾는 방법

Oct 21, 2025 — general-binary-search

문제 설명

풀이 아이디어

해결 전략

구현

/**
* @param {number[]} citations
* @return {number}
*/
var hIndex = function(citations) {
const N = citations.length;
citations.sort((a,b) => a - b);
let left = 0;
let right = Math.max(...citations);
const isOK = (index) => {
let count = 0;
for (let i = 0; i < N; i += 1) {
if (index <= citations[i]) count += 1;
}
return index <= count;
}
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (isOK(mid)) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return right;
};