코테

[Algorithm] H-Index - JavaScript

뚜따따 2024. 2. 21. 21:39

프로그래머스 - H-Index

난이도 : Level 2
정답률: 63%

▶ 문제

▶ 풀이

정답률에 비해 쉽게 풀었다. count 가 h 번 인용된 논문이 h 편 이상인 최댓값이기 때문에 최댓값부터 감소시키며 계산했다.

function solution(citations) {
    let h = citations.length + 1;
    let count = 0;
    while(h--) {
        count = 0;
        citations.forEach(x => {
            if(h <= x) {
                count++;
            }
        })
        if(count >= h) {
            return h;
        } 
    }
}