본문 바로가기
알고리즘 & 자료구조/프로그래머스

H-Index

by 신재권 2023. 1. 11.
package programmers;

import java.util.Arrays;

public class H_Index {

   //h-index = 논문 n 편중 h번 인용된 논문이 h편 이상이고, 나머지 논문이 h번 이하 인용되었되었을 때 최대값
   //1 <= n <= 1000
   //0 <= h <= 10000

   public static int solution(int[] citations) {
      Arrays.sort(citations);

      int len = citations[citations.length - 1];

      int max = 0;
      for (int i = 0; i <= len; i++) {
         int countA = 0;
         int countB = 0;

         for (int j = 0; j < citations.length; j++) {
            if (citations[j] <= i) {
               countA++;
            }
            if (citations[j] >= i) {
               countB++;
            }

         }
         if (countA <= i && countB >= i) {
            max = Math.max(i, max);
         }
      }

      return max;
   }

   public static void main(String[] args) {
      System.out.println(solution(new int[] {3, 0, 6, 1, 5}));
      System.out.println(solution(new int[] {3, 0, 6, 1, 5, 7}));
   }
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

행렬의 곱셈  (0) 2023.01.13
캐시  (0) 2023.01.12
멀리 뛰기  (0) 2023.01.10
점프와 순간이동  (0) 2023.01.08
예상 대진표  (1) 2023.01.07