[프로그래머스/C++] H-index

mani·2023년 4월 13일
0

H-index

greater<int> ()

문제 이해

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int solution(vector<int> citations) {
    int answer = 0;

    sort(citations.begin(), citations.end(), greater<int>());
    answer = citations[0];
    
    for (int i = 0; i < citations.size(); ++i) {
        if (citations[i] < i + 1) {
            return i;
        }
    }
    return citations.size();
}
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int solution(vector<int> citations) {
    int answer = 0;

    sort(citations.begin(), citations.end(), greater<int>());
    answer = citations[0];
    
    while(answer){
        int h=0;
        for(int i=0;i<citations.size();i++){
            if(citations[i]>=answer){
                h++;
            }
            if(answer == h) return answer;
        }
        answer--;
    }
    return answer;
}
profile
log

0개의 댓글