Algorithm

[020] H-Index

JEE-JEEE 2024. 2. 27. 14:54

https://school.programmers.co.kr/learn/courses/30/lessons/42747

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 


 

풀이

h-index 를 구하는 방법은

1. 들어온 citations를 오름차순으로 정렬한다.

2. 반복문을 통해서 제일 마지막 - i 에 해당하는 h의 정보를 현재 citations와 같은지 비교한다.

3. 현재 citations[i]의 수가 h보다 크거나 같다면 그것이 h-index이기 때문에 해당하는 h를 리턴한다

 

간단한 정렬 및 검증이기 때문에 큰 풀이 과정이 필요하지 않았다 (...)

 

    public int t12(int[] citations) {
        int answer = 0;

        Arrays.sort(citations);
        for(int i = 0; i < citations.length; i ++){
            int h = citations.length - i;

            if(citations[i] >= h){
                answer = h;
                break;
            }
        }
        return answer;
    }