H_Index https://programmers.co.kr/learn/courses/30/lessons/42747
완전탐색
정렬, index 이용
O^N
으로 풀 수 있습니다.function solution(citations) {
let answer = 0;
const max_num = Math.max(...citations);
for (let h_index = max_num; h_index >= 0; h_index--) {
const moreCnt = citations.filter((v) => v >= h_index).length;
const lessCnt = citations.filter((v) => v <= h_index).length;
if (moreCnt >= h_index && lessCnt <= h_index) {
answer = h_index;
break;
}
}
return answer;
}
function solution(citations) {
let answer = -1;
citations.sort((a, b) => b - a);
for (let i = 0; i < citations.length; i++) {
if (citations[i] <= i) {
answer = i;
break;
}
}
if (answer === -1) answer = citations.length;
return answer;
}