334. H-Index

아현·2021년 11월 12일
0

Algorithm

목록 보기
358/400

프로그래머스

H-Index란



1. Python



def solution(citations):
    citations = sorted(citations)
    l = len(citations)
    for i in range(l):
        if citations[i] >= l-i:
            return l-i
    return 0



2. C++


#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<int> citations) {
    sort(citations.begin(), citations.end(), greater<>());
    int i = 0;
    while (i + 1 <= citations[i]) {
        i++;
    }
    return i;
}



3. JavaScript


function solution(citations) {
    citations = citations.sort((a, b) => b - a);
    //console.log(citations);
    let i = 0;
    while (i + 1 <= citations[i]) {
        i++;
    }
    return i;

}



profile
For the sake of someone who studies computer science

0개의 댓글