본문 바로가기
Beakjoon&프로그래머스/Java

[프로그래머스/Java] H-Index

by 현장 2026. 1. 12.

-Code

import java.util.*;

class Solution {
    public int solution(int[] citations) {
        int length = citations.length;
        // 정렬
        Arrays.sort(citations);
        // 현재 가리키는 논문의 인용 횟수보다 큰 논문의 갯수를 구하기
        for (int i = 0; i < length; i++) {
            if (length - i <= citations[i])  {
                return length - i;
            }
        }
        return 0;
    }
}

정렬을 하고 구하는 건 맞았으나 설명이 n, h 이렇게 되어있으니 조건을 잘못 새웠습니다. 결국 현재 인용 횟수가 남아있는 논문 개수보다 크거나 같은 경우를 구하는 문제였습니다.