JiwonKKang/[프로그래머스] H-Index - 자바

Created Sun, 03 Dec 2023 01:37:28 +0900 Modified Sun, 03 Dec 2023 23:52:17 +0900

[프로그래머스] H-Index - 자바

나의 풀이


import java.util.*;

class Solution {
    public int solution(int[] citations) {
        List<Integer> answerList = new ArrayList<>();

        Arrays.sort(citations);

        for (int i = 0; i < citations.length; i++) {
            if (citations[i] >= citations.length - i) {
                answerList.add(citations.length - i);
            }
        }
        return answerList.isEmpty() ? 0 : answerList.get(0);
    }
}

접근


  1. citations를 정렬하게되면 배열의 값이 인용횟수, citations.length-i가 인용횟수 이상의 논문 갯수
  2. 논문의 갯수가 H-Index

삽질


  • 논문의 갯수를 리턴해야하는데 계속 논문인용횟수를 리턴해서 테스트 케이스를 통과하지못했다;;