본문 바로가기
Study Note/Algorithm

프로그래머스 #정렬 - H-Index lv2

by 시뮝 2021. 9. 12.
728x90

문제

 

풀이

function solution(citations) {
    var answer = 0;
    let sortCitations = citations.sort((a, b) => a - b);
    let len = sortCitations.length;

    for(let i=0; i<len; i++) {
        const citation = sortCitations[i];
        const cnt = citations.filter((c) => c >= citation).length;
        
        if(citation >= cnt) {
            answer = len - i;
            break;
        }
    }
    
    return answer;
}

 

채점결과

 

728x90

댓글