[プログラマー]H-Index


質問リンク:プログラマ-ソート>H-Index

プール1(py)

def solution(citations):
    answer = 0
    citations.sort() 
    h = citations[-1]
    idx = 0
    
    while h >= 0:
        for i in range(len(citations)):
            if citations[i] >= h:
                idx = i
                break
        if len(citations) - idx >= h and idx <= h:
            return h
        
        h -= 1

    return answer

プール2(js)

function solution(citations) {
    var n = Math.max(...citations);
    const LENGTH = citations.length;
    
    for (let h = n; h >= 0; h--){
        let cnt = citations.filter((citation) => citation >= h).length;
        if (cnt >= h && LENGTH - cnt <= h){
            return h;
        }        
    }
}