[C++] 프로그래머스 Lv.2 H-Index

임시 개발자·2023년 2월 12일
0

프로그래머스

목록 보기
3/5

문제 링크

풀이 방법

  • citations 벡터를 정렬한다.
  • n-i를 통해서 인용 수를 계산한다.
  • citations[i]가 인용 수 이상이면 H-index를 값으로 정한다.
  • H-index가 정해지면 그보다 더 높은 값을 찾을 수 없으므로 break 한다.

코드

int solution(vector<int> citations) {
	int answer = 0;
	int n = citations.size();
	sort(citations.begin(), citations.end());


	for (int i = 0; i < n; i++)
	{
		int h = n - i;
		if (citations[i] >= h)
		{
			answer = h;
			break;
		}
	}


	return answer;
}
profile
클라이언트 프로그래머 지망

0개의 댓글