프로그래머스(Programmers)
프로그래머스 H-Index C++
cosmohoo
2022. 1. 12. 23:58
반응형

#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> citations) {
int answer = 0;
sort(citations.begin(), citations.end(), greater<int>());
if(citations[0]==0)return answer;
for(int i=0; i<citations.size(); i++)
{
if(citations[i] > i)answer++;
}
return answer;
}
=> 아래 사진을 보며 이해할 수 있습니다.
=> 우선 내림차순으로 정렬하여 비교가 편하게 합니다.

=> 각 배열에 있는 값보다(h번이상 인용된 논문)보다 더 많이 인용된 논문들의 갯수가 더 많아야합니다.
=> 그럴 경우 h의 값이 늘어나게 됩니다.
=> 규칙을 찾아야 풀 수 있는 문제였습니다.
반응형