mojo's Blog
H-Index 본문
문제 링크 => 코딩테스트 연습 - H-Index | 프로그래머스 (programmers.co.kr)
코딩테스트 연습 - H-Index
H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 어떤 과학자가 발표
programmers.co.kr
풀이 Code
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool compare(int x, int y) {
return x > y;
}
int solution(vector<int> citations) {
int answer = 0;
sort(citations.begin(), citations.end(), compare);
int size = citations.size(), op = 0;
for (int i = 0; i < size; i++) {
if ((i + 1) <= citations[i]) answer = i + 1;
else {
op = 1;
break;
}
}
if (op == 0) return citations.size();
return answer;
}
Comments