코딩테스트 고득점키트 분류 2급 문제에 대한 H-index 솔루션입니다. 이 문제는 정렬 부분에 있는데 논문수가 1000까지이고 인용수가 10000까지이므로 10000 * 1000 = 10000000이므로 실제로는 1초를 넘지 않습니다. 따라서 정렬은 필요하지 않습니다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> citations) {
int answer = 0;
int citaSize = citations.size();
sort(citations.begin(), citations.end());
for (int h = 0; h <= 10000; h++)
{
int orMore = 0;
for (auto c : citations)
{
if (c >= h)
{
orMore++;
}
}
if (orMore >= h && citaSize - orMore <= h)
{
answer = h;
}
}
return answer;
}